Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions crates/iceberg/src/writer/file_writer/parquet_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ impl MinMaxColAggregator {
));
};

self.update_state_min(field_id, min_datum);
// Iceberg bounds must not be NaN.
if !min_datum.is_nan() {
self.update_state_min(field_id, min_datum);
}
Comment on lines +383 to +385

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this as is. Each guard is a single !is_nan() check, so a helper would save one line per call site and add indirection. If more invalid-bound rules appear, a shared predicate makes sense then.

}

if value.max_is_exact() {
Expand All @@ -390,7 +393,9 @@ impl MinMaxColAggregator {
));
};

self.update_state_max(field_id, max_datum);
if !max_datum.is_nan() {
self.update_state_max(field_id, max_datum);
}
Comment on lines +396 to +398

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the min case above: leaving the guard inline.

}

Ok(())
Expand Down Expand Up @@ -2605,6 +2610,40 @@ mod tests {
assert_eq!(upper_bounds, HashMap::from([(0, Datum::int(i32::MAX))]));
}

#[test]
fn test_min_max_aggregator_skips_nan_bounds() {
let schema = Arc::new(
Schema::builder()
.with_schema_id(1)
.with_fields(vec![
NestedField::required(0, "f", Type::Primitive(PrimitiveType::Float)).into(),
NestedField::required(1, "d", Type::Primitive(PrimitiveType::Double)).into(),
])
.build()
.expect("Failed to create schema"),
);
let mut min_max_agg = MinMaxColAggregator::new(schema);
let float_stats =
|min, max| Statistics::Float(ValueStatistics::new(min, max, None, None, false));
let double_stats =
|min, max| Statistics::Double(ValueStatistics::new(min, max, None, None, false));

min_max_agg
.update(0, &float_stats(Some(-f32::NAN), Some(f32::NAN)))
.unwrap();
min_max_agg
.update(0, &float_stats(Some(1.5), Some(2.5)))
.unwrap();
min_max_agg
.update(1, &double_stats(Some(f64::NAN), Some(f64::NAN)))
.unwrap();

let (lower_bounds, upper_bounds) = min_max_agg.produce();

assert_eq!(lower_bounds, HashMap::from([(0, Datum::float(1.5_f32))]));
assert_eq!(upper_bounds, HashMap::from([(0, Datum::float(2.5_f32))]));
}

fn cdc_test_schema() -> SchemaRef {
Arc::new(
Schema::builder()
Expand Down
Loading