private void removeTimeFilters(List<Expression> expressions, Expression expression) { if (expression.op() == Operation.AND) { And and = (And) expression; removeTimeFilters(expressions, and.left()); removeTimeFilters(expressions, and.right()); return; } else if (expression instanceof UnboundPredicate) { UnboundPredicate pred = (UnboundPredicate) expression; NamedReference ref = (NamedReference) pred.ref(); Literal<?> lit = pred.literal(); if (TIMESTAMP_NAMES.contains(ref.name())) { Literal<Long> tsLiteral = lit.to(Types.TimestampType.withoutZone()); long millis = toMillis(tsLiteral.value()); addTimestampFilter(Expressions.predicate(pred.op(), "timestamp_ms", millis)); return; } } expressions.add(expression); }
@Test public void testInvalidBinaryConversions() { testInvalidConversions(Literal.of(ByteBuffer.wrap(new byte[] {0, 1, 2})), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 2), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1) ); }
@Test public void testInvalidUUIDConversions() { testInvalidConversions(Literal.of(UUID.randomUUID()), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 2), Types.StringType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testInvalidTimeConversions() { testInvalidConversions( Literal.of("14:21:01.919").to(Types.TimeType.get()), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 4), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testInvalidFixedConversions() { testInvalidConversions(Literal.of(new byte[] {0, 1, 2}), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 2), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1) ); }
@Test public void testInvalidDateConversions() { testInvalidConversions(Literal.of("2017-08-18").to(Types.DateType.get()), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 4), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testInvalidBooleanConversions() { testInvalidConversions(Literal.of(true), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 2), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testInvalidTimestampConversions() { testInvalidConversions( Literal.of("2017-08-18T14:21:01.919").to(Types.TimestampType.withoutZone()), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.TimeType.get(), Types.DecimalType.of(9, 4), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testTimestampWithoutZoneToHumanString() { Types.TimestampType type = Types.TimestampType.withoutZone(); Literal<Integer> date = Literal.of("2017-12-01T10:12:55.038194").to(type); Transform<Integer, Integer> year = Transforms.year(type); Assert.assertEquals("Should produce the correct Human string", "2017", year.toHumanString(year.apply(date.value()))); Transform<Integer, Integer> month = Transforms.month(type); Assert.assertEquals("Should produce the correct Human string", "2017-12", month.toHumanString(month.apply(date.value()))); Transform<Integer, Integer> day = Transforms.day(type); Assert.assertEquals("Should produce the correct Human string", "2017-12-01", day.toHumanString(day.apply(date.value()))); Transform<Integer, Integer> hour = Transforms.hour(type); Assert.assertEquals("Should produce the correct Human string", "2017-12-01-10", hour.toHumanString(hour.apply(date.value()))); }
@Test public void testInvalidDoubleConversions() { testInvalidConversions(Literal.of(34.11D), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testInvalidFloatConversions() { testInvalidConversions(Literal.of(34.11F), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test @SuppressWarnings("unchecked") public void testPartitionPath() { PartitionSpec spec = PartitionSpec.builderFor(SCHEMA) .hour("ts") .bucket("id", 10) .build(); Transform hour = spec.getFieldBySourceId(3).transform(); Transform bucket = spec.getFieldBySourceId(1).transform(); Literal<Long> ts = Literal.of("2017-12-01T10:12:55.038194").to(Types.TimestampType.withoutZone()); Object tsHour = hour.apply(ts.value()); Object idBucket = bucket.apply(1); Row partition = Row.of(tsHour, idBucket); Assert.assertEquals("Should produce expected partition key", "ts_hour=2017-12-01-10/id_bucket=" + idBucket, spec.partitionToPath(partition)); }
public Builder before(String timestamp) { Literal<Long> tsLiteral = Literal.of(timestamp).to(Types.TimestampType.withoutZone()); return before(tsLiteral.value() / 1000); }
@Test public void testInvalidIntegerConversions() { testInvalidConversions(Literal.of(34), Types.BooleanType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
public Builder after(String timestamp) { Literal<Long> tsLiteral = Literal.of(timestamp).to(Types.TimestampType.withoutZone()); return after(tsLiteral.value() / 1000); }
@Test public void testTimestampWithoutZoneHumanString() { Types.TimestampType timestamp = Types.TimestampType.withoutZone(); Transform<Long, Long> identity = Transforms.identity(timestamp); String tsString = "2017-12-01T10:12:55.038194"; Literal<Long> ts = Literal.of(tsString).to(timestamp); // value is not changed Assert.assertEquals("Should produce identical timestamp without time zone", tsString, identity.toHumanString(ts.value())); }
@Test(expected = DateTimeException.class) public void testTimestampWithoutZoneWithZoneInLiteral() { // Zone must not be present in literals when converting to timestamp without zone Literal<CharSequence> timestampStr = Literal.of("2017-08-18T14:21:01.919+07:00"); timestampStr.to(Types.TimestampType.withoutZone()); }
public Builder after(String timestamp) { Literal<Long> tsLiteral = Literal.of(timestamp).to(Types.TimestampType.withoutZone()); this.startTime = tsLiteral.value() / 1000; return this; }
public Builder before(String timestamp) { Literal<Long> tsLiteral = Literal.of(timestamp).to(Types.TimestampType.withoutZone()); this.endTime = tsLiteral.value() / 1000; return this; }
private static com.netflix.iceberg.expressions.Literal<Long> tsLiteral(long timestampMicros) { return com.netflix.iceberg.expressions.Literal .of(timestampMicros) .to(TimestampType.withoutZone()); }