nastra commented on code in PR #9008:
URL: https://github.com/apache/iceberg/pull/9008#discussion_r1668493077
##########
api/src/test/java/org/apache/iceberg/expressions/TestStringLiteralConversions.java:
##########
@@ -132,6 +132,51 @@ public void testStringToTimestampLiteral() {
.isEqualTo(avroValue);
}
+ @Test
+ public void
testStringToTimestampLiteralWithMicrosecondPrecisionFromNanoseconds() {
+ // use Avro's timestamp conversion to validate the result
+ Schema avroSchema =
LogicalTypes.timestampMicros().addToSchema(Schema.create(Schema.Type.LONG));
+ TimeConversions.TimestampMicrosConversion avroConversion =
+ new TimeConversions.TimestampMicrosConversion();
+
+ Literal<CharSequence> timestampStr =
Literal.of("2017-08-18T14:21:01.123456789");
+ Literal<Long> timestamp =
timestampStr.to(Types.TimestampType.withoutZone());
+ long avroValue =
+ avroConversion.toLong(
+ LocalDateTime.of(2017, 8, 18, 14, 21, 1,
123456000).toInstant(ZoneOffset.UTC),
+ avroSchema,
+ avroSchema.getLogicalType());
+
+ assertThat((long) timestamp.value())
+ .as("Timestamp without zone should match UTC")
+ .isEqualTo(avroValue);
+ }
+
+ @Test
+ public void
testStringToTimestampLiteralWithNanosecondPrecisionFromNanoseconds() {
+ Literal<CharSequence> timestampStr =
Literal.of("2017-08-18T14:21:01.123456789");
+ Literal<Long> timestamp =
timestampStr.to(Types.TimestampNanoType.withoutZone());
+
+ // use Avro's timestamp conversion to validate the result within one
microsecond
+ Schema avroSchema =
LogicalTypes.timestampMicros().addToSchema(Schema.create(Schema.Type.LONG));
+ TimeConversions.TimestampMicrosConversion avroConversion =
+ new TimeConversions.TimestampMicrosConversion();
+ long avroValue =
+ avroConversion.toLong(
+ LocalDateTime.of(2017, 8, 18, 14, 21, 1,
123456000).toInstant(ZoneOffset.UTC),
+ avroSchema,
+ avroSchema.getLogicalType());
+ assertThat(timestamp.value() - avroValue * 1000)
+ .as("Timestamp without zone should match UTC")
+ .isLessThan(1000);
Review Comment:
should this be `.isEqualTo(789L)`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]