hcrosse commented on code in PR #3623:
URL: https://github.com/apache/iceberg-rust/pull/3623#discussion_r4776442331
##########
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:
Thanks for the review. Dropped `project_comparison_column` and both unit
tests, so `predicate_visitor.rs` now matches `main` while the end to end reader
tests still cover filtering through `get_row_filter`.
##########
crates/iceberg/src/arrow/reader/predicate_visitor.rs:
##########
@@ -278,6 +278,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(
+ batch: &RecordBatch,
+ column_idx: usize,
+) -> std::result::Result<ArrayRef, ArrowError> {
+ let column = project_column(batch, column_idx)?;
+
+ match column.data_type() {
+ DataType::Timestamp(TimeUnit::Millisecond, tz) => cast_with_options(
+ &column,
+ &DataType::Timestamp(TimeUnit::Microsecond, tz.clone()),
+ &CastOptions {
+ safe: false,
+ ..Default::default()
+ },
+ ),
+ _ => Ok(column),
+ }
+}
Review Comment:
Now that #3540 landed, I dropped the widening helper and its two unit tests
and kept the end to end reader tests.
##########
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:
Done. All four timestamp types now scale widening bounds, drop narrowing or
overflowing bounds, and convert bloom probes across row group metrics, page
indexes, and bloom filters. Added unit and end to end tests covering non
projected millisecond and microsecond columns under nanosecond fields.
##########
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:
Done. Moved both bound scaling and bloom probe unit conversion into shared
`pub(crate)` helpers in `schema.rs` using `parquet::basic::TimeUnit`, and wired
all three evaluators and footer metrics through them.
##########
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:
Good catch. Updated `MinMaxColAggregator` to drop and permanently omit only
the affected bound side for that column when a row group bound cannot be
converted, so `TIMESTAMP(NANOS)` imports under microsecond fields succeed and
partial bounds from other row groups are never emitted.
--
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]