comphead commented on code in PR #3632:
URL: https://github.com/apache/iceberg-rust/pull/3632#discussion_r4743825266
##########
crates/iceberg/src/arrow/int96.rs:
##########
@@ -348,39 +364,189 @@ mod tests {
let arrow_schema = Arc::new(ArrowSchema::new(vec![
Field::new(
"ts",
- DataType::Timestamp(TimeUnit::Nanosecond, Some("UTC".into())),
+ DataType::Timestamp(TimeUnit::Nanosecond,
Some(UTC_TIME_ZONE.into())),
true,
)
.with_metadata(field_id_meta(1)),
]));
- assert!(coerce_int96_timestamps(&arrow_schema, &iceberg).is_none());
+ assert!(
+ coerce_int96_timestamps(&arrow_schema, &iceberg, &parquet)
+ .unwrap()
+ .is_none()
+ );
}
#[test]
fn test_no_coercion_when_already_microsecond() {
+ let parquet = parquet_schema("message schema { optional int96 ts;
required int32 id; }");
let arrow_schema = Arc::new(ArrowSchema::new(vec![
Field::new("ts", DataType::Timestamp(TimeUnit::Microsecond, None),
true)
.with_metadata(field_id_meta(1)),
Field::new("id", DataType::Int32,
false).with_metadata(field_id_meta(2)),
]));
let iceberg = iceberg_schema_with_timestamp();
- assert!(coerce_int96_timestamps(&arrow_schema, &iceberg).is_none());
+ assert!(
+ coerce_int96_timestamps(&arrow_schema, &iceberg, &parquet)
+ .unwrap()
+ .is_none()
+ );
+ }
+
+ #[test]
+ fn test_no_coercion_without_int96() {
Review Comment:
No test fails when the early `return Ok(None)` above is removed, because the
visitor also returns `None` when nothing changes.
`test_only_int96_timestamps_are_coerced` already shows that non-INT96
timestamps keep their types. Could this test be dropped?
Also, every mutation `test_coercion_preserves_list_views` catches is also
caught by `test_read_int96_with_unselected_list_views` or the list tests in
`pipeline.rs`. I checked removing the list-view arms in `visit_type` and
`Int96CoercionVisitor::list`, dropping list metadata, and removing the UTC
hint. It looks safe to drop as well.
##########
crates/iceberg/src/arrow/reader/pipeline.rs:
##########
@@ -3197,12 +3749,25 @@ mod tests {
#[tokio::test]
async fn test_read_int96_timestamps_in_list() {
+ assert_read_int96_timestamps_in_list(PrimitiveType::Timestamp).await;
+ }
+
+ #[tokio::test]
+ async fn test_read_int96_timestamptz_in_list() {
Review Comment:
This case still passes with the UTC hint removed from `target_type` (the
`Timestamptz` arm returning `Timestamp(Microsecond, None)`). The test projects
only the list's one leaf. I think projection drops that leaf and takes the
read-all fallback, and `RecordBatchTransformer` then adds the timezone, while
#3611 needs a second projected column. The map variant does fail under the same
change, probably because its key leaf stays selected. Could this test either
read a sibling column, or be dropped since `test_read_int96_timestamptz_in_map`
and `test_read_int96_with_mixed_timestamp_types_in_struct` already cover nested
`timestamptz`?
##########
crates/iceberg/src/arrow/reader/pipeline.rs:
##########
@@ -1065,30 +1071,48 @@ mod tests {
file_path: &str,
schema: SchemaRef,
project_field_ids: Vec<i32>,
+ ) -> Vec<RecordBatch> {
+ read_int96_batches_with_name_mapping(file_path, schema,
project_field_ids, None).await
+ }
+
+ async fn read_int96_batches_with_name_mapping(
+ file_path: &str,
+ schema: SchemaRef,
+ project_field_ids: Vec<i32>,
+ name_mapping: Option<Arc<NameMapping>>,
) -> Vec<RecordBatch> {
let file_io = FileIO::new_with_fs();
let reader = ArrowReaderBuilder::new(file_io,
Runtime::current()).build();
+ let task = int96_scan_task(file_path, schema, project_field_ids,
name_mapping);
+ let tasks = Box::pin(futures::stream::iter(vec![Ok(task)])) as
FileScanTaskStream;
+ reader
+ .read(tasks)
+ .unwrap()
+ .stream()
+ .try_collect()
+ .await
+ .unwrap()
+ }
+
+ fn int96_scan_task(
Review Comment:
`int96_scan_task` has one caller, `read_int96_batches_with_name_mapping`.
Could it be inlined back? The helper also reads the INT64 nanosecond file now,
so `read_batches_with_name_mapping` might be a more accurate name.
##########
crates/iceberg/src/arrow/reader/projection.rs:
##########
@@ -84,6 +84,11 @@ impl ArrowReader {
(Some(lhs), Some(rhs)) if lhs == rhs => true,
(Some(PrimitiveType::Int), Some(PrimitiveType::Long)) => true,
(Some(PrimitiveType::Float), Some(PrimitiveType::Double)) =>
true,
+ // Not a spec type promotion. Migrated files (for example from
`add_files`) can
+ // store `TIMESTAMP(NANOS)` under a microsecond field, and
`RecordBatchTransformer`
+ // casts them to microseconds.
+ (Some(PrimitiveType::TimestampNs),
Some(PrimitiveType::Timestamp))
+ | (Some(PrimitiveType::TimestamptzNs),
Some(PrimitiveType::Timestamptz)) => true,
Review Comment:
This arm lets an INT64 `TIMESTAMP(NANOS)` column through projection, so
these files now read correctly without a filter. A filtered scan of the same
file still drops matching rows, because row-group pruning reads the nanosecond
min/max as microseconds. `get_parquet_stat_min_as_datum` and
`get_parquet_stat_max_as_datum` in `arrow/schema.rs` pick the unit from the
Iceberg type, and `row_group_metrics_evaluator.rs:143` passes the Iceberg type.
`int64_bound_to_datum` in `page_index_evaluator.rs` does the same for page
bounds.
I added this next to `test_predicate_on_promoted_column` in `row_filter.rs`
and ran it on this branch:
```rust
assert_promoted_reads(
Arc::new(TimestampNanosecondArray::from(vec![1_000_000_000])),
PrimitiveType::Timestamp,
Reference::new("v").less_than(Datum::timestamp_micros(2_000_000)),
Some(Arc::new(TimestampMicrosecondArray::from(vec![1_000_000]))),
)
.await;
```
It returns no rows. The min of 1s in nanoseconds reads as about 16 minutes
in microseconds, so `v < 2s` prunes the row group. With
`row_group_filtering_enabled(false)` the same read returns the row.
The pruning code predates this PR. But #3616 is about reading these files,
and with this PR that read works only without a filter. Could the stats path
return `None` when the Parquet column's timestamp unit is finer than the
Iceberg type's, or could #3616 stay open with a follow-up issue for pruning?
--
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]