raminqaf commented on code in PR #29050:
URL: https://github.com/apache/flink/pull/29050#discussion_r3913300979


##########
flink-core/src/test/java/org/apache/flink/types/variant/BinaryVariantTest.java:
##########
@@ -99,10 +100,51 @@ void testScalarVariant() {
         assertThat(builder.of(localDate).getDate()).isEqualTo(localDate);
         assertThat(builder.of(localDate).get()).isEqualTo(localDate);
 
+        LocalTime localTime = LocalTime.now().truncatedTo(ChronoUnit.MICROS);
+        assertThat(builder.of(localTime).getTime()).isEqualTo(localTime);
+        assertThat(builder.of(localTime).get()).isEqualTo(localTime);
+
         assertThat(builder.ofNull().get()).isEqualTo(null);
         assertThat(builder.ofNull().isNull()).isTrue();
     }
 
+    @Test
+    void testNanosecondPrecisionVariant() {
+        // Microsecond-precision values keep using the compact 
TIMESTAMP/TIMESTAMP_LTZ encoding,
+        // matching the pre-existing on-wire format.
+        Instant microInstant = Instant.now().truncatedTo(ChronoUnit.MICROS);
+        
assertThat(builder.of(microInstant).getType()).isEqualTo(Variant.Type.TIMESTAMP_LTZ);
+        
assertThat(builder.of(microInstant).getInstant()).isEqualTo(microInstant);
+
+        LocalDateTime microLocalDateTime = 
LocalDateTime.now().truncatedTo(ChronoUnit.MICROS);
+        
assertThat(builder.of(microLocalDateTime).getType()).isEqualTo(Variant.Type.TIMESTAMP);
+        
assertThat(builder.of(microLocalDateTime).getDateTime()).isEqualTo(microLocalDateTime);
+
+        // Sub-microsecond precision must switch to the nanosecond-precision 
encoding rather than
+        // silently truncating.
+        Instant nanoInstant = 
Instant.now().truncatedTo(ChronoUnit.NANOS).plusNanos(123);
+        Variant instantVariant = builder.of(nanoInstant);
+        
assertThat(instantVariant.getType()).isEqualTo(Variant.Type.TIMESTAMP_LTZ_NS);
+        assertThat(instantVariant.getInstantNanos()).isEqualTo(nanoInstant);
+        assertThat(instantVariant.get()).isEqualTo(nanoInstant);
+        
assertThatThrownBy(instantVariant::getInstant).isInstanceOf(VariantTypeException.class);
+
+        LocalDateTime nanoLocalDateTime = 
LocalDateTime.now().withNano(123456789);
+        Variant dateTimeVariant = builder.of(nanoLocalDateTime);
+        
assertThat(dateTimeVariant.getType()).isEqualTo(Variant.Type.TIMESTAMP_NS);
+        
assertThat(dateTimeVariant.getDateTimeNanos()).isEqualTo(nanoLocalDateTime);
+        assertThat(dateTimeVariant.get()).isEqualTo(nanoLocalDateTime);
+        
assertThatThrownBy(dateTimeVariant::getDateTime).isInstanceOf(VariantTypeException.class);

Review Comment:
   Can you please file a bug ticket for this so we can have it fixed?



-- 
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]

Reply via email to