Akash3121 commented on code in PR #10601:
URL: https://github.com/apache/paimon/pull/10601#discussion_r4290936416


##########
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));

Review Comment:
   [P1] Encode Iceberg `timestamp` columns as `MICROS` too
     
    Iceberg requires `INT64 TIMESTAMP_MICROS` for both  timestamp  and  
timestamptz , not only the zoned type. Paimon's Iceberg schema conversion 
publishes `TIMESTAMP(3)` as  timestamp , so retaining `MILLIS` here still 
produces a Parquet file that strict Iceberg readers reject whenever the table 
has an ordinary `TIMESTAMP(3)` column. Please apply the Iceberg-gated MICROS 
encoding to `TIMESTAMP_WITHOUT_TIME_ZONE` as well and assert that both columns 
use MICROS; the non-Iceberg default can remain unchanged.



##########
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:
   [P2] Preserve predicate pushdown for the new MICROS representation
     
   This does not currently exercise predicate pushdown: 
`ParquetFilters.timestampColumn` expects `MILLIS` for a precision-3 field, 
rejects this file's `MICROS` annotation, and `ParquetFilters.convert` silently 
drops the predicate. As a result, all row groups in newly written Iceberg files 
are scanned for timestamp filters. Please convert timestamp literals using the 
actual file annotation (while retaining the `adjustedToUTC` compatibility 
check) and add a multi-row-group test that verifies a nonmatching row group is 
pruned.



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