@SuppressWarnings("unchecked") private static <T> void updateMin(Map<Integer, Literal<?>> lowerBounds, int id, Literal<T> min) { Literal<T> currentMin = (Literal<T>) lowerBounds.get(id); if (currentMin == null || min.comparator().compare(min.value(), currentMin.value()) < 0) { lowerBounds.put(id, min); } }
@Override public <T> Boolean eq(BoundReference<T> ref, Literal<T> lit) { Comparator<T> cmp = lit.comparator(); return cmp.compare(ref.get(struct), lit.value()) == 0; }
@Override public <T> Boolean lt(BoundReference<T> ref, Literal<T> lit) { Comparator<T> cmp = lit.comparator(); return cmp.compare(ref.get(struct), lit.value()) < 0; }
@Override public <T> Boolean gt(BoundReference<T> ref, Literal<T> lit) { Comparator<T> cmp = lit.comparator(); return cmp.compare(ref.get(struct), lit.value()) > 0; }
@Override public <T> Boolean eq(BoundReference<T> ref, Literal<T> lit) { Integer id = ref.fieldId(); Types.NestedField field = struct.field(id); Preconditions.checkNotNull(field, "Cannot filter by nested column: %s", schema.findField(id)); Boolean hasNonDictPage = isFallback.get(id); if (hasNonDictPage == null || hasNonDictPage) { return ROWS_MIGHT_MATCH; } Set<T> dictionary = dict(id, lit.comparator()); return dictionary.contains(lit.value()) ? ROWS_MIGHT_MATCH : ROWS_CANNOT_MATCH; }
@Override public <T> Expression ltEq(BoundReference<T> ref, Literal<T> lit) { Comparator<T> cmp = lit.comparator(); return (cmp.compare(ref.get(struct), lit.value()) <= 0) ? alwaysTrue() : alwaysFalse(); }
@Override public <T> Expression gtEq(BoundReference<T> ref, Literal<T> lit) { Comparator<T> cmp = lit.comparator(); return (cmp.compare(ref.get(struct), lit.value()) >= 0) ? alwaysTrue() : alwaysFalse(); }
public Builder after(String timestamp) { Literal<Long> tsLiteral = Literal.of(timestamp).to(Types.TimestampType.withoutZone()); this.startTime = tsLiteral.value() / 1000; return this; }
@Override public <T> Expression lt(BoundReference<T> ref, Literal<T> lit) { Comparator<T> cmp = lit.comparator(); return (cmp.compare(ref.get(struct), lit.value()) < 0) ? alwaysTrue() : alwaysFalse(); }
@Override public <T> Expression gt(BoundReference<T> ref, com.netflix.iceberg.expressions.Literal<T> lit) { return column(ref).gt(lit.value()).expr(); }
public Builder before(String timestamp) { Literal<Long> tsLiteral = Literal.of(timestamp).to(Types.TimestampType.withoutZone()); this.endTime = tsLiteral.value() / 1000; return this; }
private <T> void checkValue(Literal<T> lit) throws Exception { Literal<T> copy = TestHelpers.roundTripSerialize(lit); Assert.assertEquals("Literal's comparator should consider values equal", 0, lit.comparator().compare(lit.value(), copy.value())); Assert.assertEquals("Copy's comparator should consider values equal", 0, copy.comparator().compare(lit.value(), copy.value())); } }
private void testInvalidConversions(Literal<?> lit, Type... invalidTypes) { for (Type type : invalidTypes) { Assert.assertNull( lit.value().getClass().getName() + " literal to " + type + " is not allowed", lit.to(type)); } }
@Override public UnboundPredicate<Integer> projectStrict(String name, BoundPredicate<T> predicate) { switch (predicate.op()) { case NOT_EQ: // TODO: need to translate not(eq(...)) into notEq in expressions return Expressions.predicate(predicate.op(), name, apply(predicate.literal().value())); // case NOT_IN: // return null; default: // no strict projection for comparison or equality return null; } }
@Test public void testLongToDecimalConversion() { Literal<Long> lit = Literal.of(34L); Assert.assertEquals("Value should match", new BigDecimal("34"), lit.to(Types.DecimalType.of(9, 0)).value()); Assert.assertEquals("Value should match", new BigDecimal("34.00"), lit.to(Types.DecimalType.of(9, 2)).value()); Assert.assertEquals("Value should match", new BigDecimal("34.0000"), lit.to(Types.DecimalType.of(9, 4)).value()); }
@Test public void testFloatToDecimalConversion() { Literal<Float> lit = Literal.of(34.56F); Assert.assertEquals("Value should round using HALF_UP", new BigDecimal("34.6"), lit.to(Types.DecimalType.of(9, 1)).value()); Assert.assertEquals("Value should match", new BigDecimal("34.56"), lit.to(Types.DecimalType.of(9, 2)).value()); Assert.assertEquals("Value should match", new BigDecimal("34.5600"), lit.to(Types.DecimalType.of(9, 4)).value()); }
@Test public void testStringToUUIDLiteral() { UUID expected = UUID.randomUUID(); Literal<CharSequence> uuidStr = Literal.of(expected.toString()); Literal<UUID> uuid = uuidStr.to(Types.UUIDType.get()); Assert.assertEquals("UUID should match", expected, uuid.value()); }
@Test public void testBinaryToFixed() { Literal<ByteBuffer> lit = Literal.of(ByteBuffer.wrap(new byte[] {0, 1, 2})); Literal<ByteBuffer> fixedLit = lit.to(Types.FixedType.ofLength(3)); Assert.assertNotNull("Should allow conversion to correct fixed length", fixedLit); Assert.assertEquals("Conversion should not change value", lit.value().duplicate(), fixedLit.value().duplicate()); Assert.assertNull("Should not allow conversion to different fixed length", lit.to(Types.FixedType.ofLength(4))); Assert.assertNull("Should not allow conversion to different fixed length", lit.to(Types.FixedType.ofLength(2))); }
@Test public void testIntegerToLongConversion() { Literal<Integer> lit = Literal.of(34); Literal<Long> longLit = lit.to(Types.LongType.get()); Assert.assertEquals("Value should match", 34L, (long) longLit.value()); }
@Test public void testTimestampWithZoneHumanString() { Types.TimestampType timestamptz = Types.TimestampType.withZone(); Transform<Long, Long> identity = Transforms.identity(timestamptz); Literal<Long> ts = Literal.of("2017-12-01T10:12:55.038194-08:00").to(timestamptz); // value will always be in UTC Assert.assertEquals("Should produce timestamp with time zone adjusted to UTC", "2017-12-01T18:12:55.038194Z", identity.toHumanString(ts.value())); }