rich7420 commented on code in PR #3623:
URL: https://github.com/apache/iceberg-rust/pull/3623#discussion_r4775323409


##########
crates/iceberg/src/writer/file_writer/parquet_writer.rs:
##########
@@ -483,9 +483,10 @@ impl MinMaxColAggregator {
             return Ok(());
         };
         let ty = ty.clone();
+        let timestamp_unit = parquet_timestamp_unit(column.column_descr());
 
         if value.min_is_exact() {
-            let Some(min_datum) = get_parquet_stat_min_as_datum(&ty, value)? 
else {
+            let Some(min_datum) = get_parquet_stat_min_as_datum(&ty, value, 
timestamp_unit)? else {

Review Comment:
   Should `MinMaxColAggregator::update` drop the bound instead of returning 
`ErrorKind::Unexpected` when `get_parquet_stat_min_as_datum` returns `None`? 
Importing a migrated `TIMESTAMP(NANOS)` file under a microsecond field fails 
here even though `ArrowReader` supports it.



##########
crates/iceberg/src/arrow/reader/predicate_visitor.rs:
##########
@@ -525,6 +525,27 @@ fn project_column(
     }
 }
 
+/// Like [`project_column`], but widens millisecond timestamps to microseconds 
so
+/// comparisons with microsecond literals keep their precision.
+fn project_comparison_column(

Review Comment:
   Now that #3540 landed and `get_row_filter` transforms filter batches to the 
table schema, can we drop `project_comparison_column` and its two unit tests? 
Keeping it leaves dead code that contradicts `try_cast_literal`.



##########
crates/iceberg/src/arrow/schema.rs:
##########
@@ -1073,9 +1074,32 @@ pub(crate) fn get_arrow_datum(datum: &Datum) -> 
Result<Arc<dyn ArrowDatum + Send
     }
 }
 
+pub(crate) fn parquet_timestamp_unit(column: &ColumnDescriptor) -> 
Option<TimeUnit> {
+    match (column.logical_type_ref(), column.converted_type()) {
+        (Some(LogicalType::Timestamp(timestamp)), _) => Some(match 
timestamp.unit {
+            ParquetTimeUnit::MILLIS => TimeUnit::Millisecond,
+            ParquetTimeUnit::MICROS => TimeUnit::Microsecond,
+            ParquetTimeUnit::NANOS => TimeUnit::Nanosecond,
+        }),
+        (None, ConvertedType::TIMESTAMP_MILLIS) => Some(TimeUnit::Millisecond),
+        (None, ConvertedType::TIMESTAMP_MICROS) => Some(TimeUnit::Microsecond),
+        _ => None,
+    }
+}
+
+pub(crate) fn parquet_timestamp_to_micros(value: i64, unit: Option<TimeUnit>) 
-> Option<i64> {

Review Comment:
   Could we move both bound scaling and bloom-probe unit conversion into shared 
helpers in `schema.rs` covering all four timestamp types? That keeps all three 
evaluators in sync and avoids duplicating the unit matches.



##########
crates/iceberg/src/arrow/schema.rs:
##########
@@ -1097,12 +1121,14 @@ pub(crate) fn get_parquet_stat_min_as_datum(
 
             Some(Datum::time_micros(*val)?)
         }
-        (PrimitiveType::Timestamp, Statistics::Int64(stats)) => {
-            stats.min_opt().map(|val| Datum::timestamp_micros(*val))
-        }
-        (PrimitiveType::Timestamptz, Statistics::Int64(stats)) => {
-            stats.min_opt().map(|val| Datum::timestamptz_micros(*val))
-        }
+        (PrimitiveType::Timestamp, Statistics::Int64(stats)) => stats
+            .min_opt()
+            .and_then(|val| parquet_timestamp_to_micros(*val, timestamp_unit))
+            .map(Datum::timestamp_micros),
+        (PrimitiveType::Timestamptz, Statistics::Int64(stats)) => stats
+            .min_opt()
+            .and_then(|val| parquet_timestamp_to_micros(*val, timestamp_unit))
+            .map(Datum::timestamptz_micros),
         (PrimitiveType::TimestampNs, Statistics::Int64(stats)) => {

Review Comment:
   Could `TimestampNs` and `TimestamptzNs` also scale or drop bounds using 
`timestamp_unit` across `schema.rs`, `page_index_evaluator.rs`, and 
`bloom_filter_evaluator.rs`? Filtering a non-projected `TIMESTAMP(MILLIS)` 
column currently prunes matching rows under nanosecond fields.



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

Reply via email to