0dunay0 commented on code in PR #10601:
URL: https://github.com/apache/paimon/pull/10601#discussion_r4324495534


##########
paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFormatReadWriteTest.java:
##########
@@ -667,4 +672,85 @@ public void 
testMissingDottedTopLevelFieldWithNoCollisionIsStillPushedDown()
                 .as("every row must survive: `x.y` is simply absent, with 
nothing to collide with")
                 .containsExactlyInAnyOrder(1L, 2L);
     }
+
+    @Test
+    public void testIcebergTimestampMicros() throws Exception {
+        Options options = new Options();
+        options.set("metadata.iceberg.storage", "table-location");
+        ParquetFileFormat format =
+                new ParquetFileFormat(new 
FileFormatFactory.FormatContext(options, 1024, 1024));
+        RowType rowType =
+                RowType.builder()
+                        .field("local_timestamp", DataTypes.TIMESTAMP(3))
+                        .field("utc_timestamp", 
DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(3))
+                        .build();
+        Timestamp min = Timestamp.fromEpochMillis(1691827200123L);
+        Timestamp max = Timestamp.fromEpochMillis(1691827200456L);
+
+        // repeated values, so that the columns are dictionary encoded
+        write(
+                format.createWriterFactory(rowType),
+                file,
+                GenericRow.of(min, min),
+                GenericRow.of(max, max),
+                GenericRow.of(min, min));
+
+        // Iceberg requires MICROS for timestamptz, timestamp without time 
zone is unchanged
+        try (ParquetFileReader reader =
+                ParquetUtil.getParquetReader(
+                        fileIO, file, fileIO.getFileSize(file), new 
Options())) {
+            MessageType schema = 
reader.getFooter().getFileMetaData().getSchema();
+            
Assertions.assertThat(schema.getType("local_timestamp").getLogicalTypeAnnotation())
+                    .isEqualTo(
+                            LogicalTypeAnnotation.timestampType(
+                                    false, 
LogicalTypeAnnotation.TimeUnit.MILLIS));
+            
Assertions.assertThat(schema.getType("utc_timestamp").getLogicalTypeAnnotation())
+                    .isEqualTo(
+                            LogicalTypeAnnotation.timestampType(
+                                    true, 
LogicalTypeAnnotation.TimeUnit.MICROS));
+            
Assertions.assertThat(reader.getFooter().getBlocks().get(0).getColumns().get(1))
+                    .satisfies(
+                            column ->
+                                    
Assertions.assertThat(column.getEncodings())
+                                            .anyMatch(e -> 
e.name().contains("DICTIONARY")));
+        }
+
+        // values are read back unchanged, also with a predicate on the MICROS 
column
+        InternalRowSerializer serializer = new InternalRowSerializer(rowType);
+        PredicateBuilder builder = new PredicateBuilder(rowType);
+        List<InternalRow> rows = new ArrayList<>();
+        try (RecordReader<InternalRow> reader =
+                format.createReaderFactory(rowType, rowType, 
Collections.emptyList())
+                        .createReader(
+                                new FormatReaderContext(
+                                        fileIO, file, 
fileIO.getFileSize(file), null, null))) {
+            reader.forEachRemaining(row -> rows.add(serializer.copy(row)));
+        }
+        Assertions.assertThat(rows).hasSize(3);
+        Assertions.assertThat(rows.get(1).getTimestamp(1, 3)).isEqualTo(max);
+        rows.clear();
+        try (RecordReader<InternalRow> reader =
+                format.createReaderFactory(
+                                rowType, rowType, 
Collections.singletonList(builder.equal(1, max)))
+                        .createReader(
+                                new FormatReaderContext(
+                                        fileIO, file, 
fileIO.getFileSize(file), null, null))) {
+            reader.forEachRemaining(row -> rows.add(serializer.copy(row)));
+        }
+        // the predicate only prunes row groups, so the row group holding the 
match is kept
+        Assertions.assertThat(rows).hasSize(3);

Review Comment:
   `ParquetFilters` now converts literals using the file's annotated unit and 
keeps the `adjustedToUTC` check. A `precision <= 3` field reads a `MICROS` 
value as `floor(v / 1000) ms`, so comparisons are widened to the micros of the 
literal millisecond: = becomes `[ms*1000, ms*1000+999]`.



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