mbutrovich opened a new issue, #3809: URL: https://github.com/apache/iceberg-rust/issues/3809
### Is your feature request related to a problem or challenge? `IS NULL` and `IS NOT NULL` on a Variant, list, map, or struct field fail to bind with `Accessor for Field <name> not found` ([`term.rs`](https://github.com/apache/iceberg-rust/blob/30b5693461220ddd133619d1261b51823210ae2f/crates/iceberg/src/expr/term.rs#L322-L324)). [`Schema::build_accessors`](https://github.com/apache/iceberg-rust/blob/30b5693461220ddd133619d1261b51823210ae2f/crates/iceberg/src/spec/schema/mod.rs#L199-L224) builds accessors only for primitive fields and the primitive fields of structs. A predicate on a field inside a struct, such as `s.x IS NULL`, binds. The spec defines [`null_value_counts`](https://github.com/apache/iceberg/blob/9203eaff9eb97fef9d1f5a3ef4460e8453adaed9/format/spec.md?plain=1#L902) by column id and says [when a Variant is null](https://github.com/apache/iceberg/blob/9203eaff9eb97fef9d1f5a3ef4460e8453adaed9/format/spec.md?plain=1#L1173), so these predicates have a defined meaning. iceberg-java binds them because it builds an accessor for every struct field, whatever its type ([`Accessors.java`](https://github.com/apache/iceberg/blob/9203eaff9eb97fef9d1f5a3ef4460e8453adaed9/api/src/main/java/org/apache/iceberg/Accessors.java#L214-L232)). Spark infers `isnotnull(data)` from a predicate such as `try_variant_get(data, '$.num', 'int') > 30`, and Iceberg includes it in the scan's residual. A downstream engine that passes residuals to `ArrowReader` has to leave these checks out. apache/datafusion-comet#7575 does, and drops the whole residual when one of them is a conjunct, so the other conjuncts lose row-group and page pruning. The following test fails on `main` at 30b5693. Add it to the `tests` module in `crates/iceberg/src/expr/predicate.rs`: ```rust #[test] fn test_bind_null_checks_on_non_primitive_fields() { use crate::spec::{ListType, MapType, StructType, VariantType}; let schema = Arc::new( Schema::builder() .with_fields(vec![ NestedField::optional(1, "v", Type::Variant(VariantType)).into(), NestedField::optional( 2, "l", Type::List(ListType::new( NestedField::list_element(3, Type::Primitive(PrimitiveType::Int), false) .into(), )), ) .into(), NestedField::optional( 4, "m", Type::Map(MapType::new( NestedField::map_key_element(5, Type::Primitive(PrimitiveType::String)) .into(), NestedField::map_value_element(6, Type::Primitive(PrimitiveType::Int), false) .into(), )), ) .into(), NestedField::optional( 7, "s", Type::Struct(StructType::new(vec![ NestedField::optional(8, "x", Type::Primitive(PrimitiveType::Int)).into(), ])), ) .into(), ]) .build() .unwrap(), ); let failures: Vec<String> = ["v", "l", "m", "s", "s.x"] .into_iter() .flat_map(|name| [Reference::new(name).is_null(), Reference::new(name).is_not_null()]) .filter_map(|expr| { expr.clone() .bind(schema.clone(), true) .err() .map(|e| format!("{expr}: {}", e.message())) }) .collect(); assert!(failures.is_empty(), "{failures:#?}"); } ``` Run `cargo test -p iceberg --lib test_bind_null_checks_on_non_primitive_fields`. It fails with: ``` [ "v IS NULL: Accessor for Field v not found", "v IS NOT NULL: Accessor for Field v not found", "l IS NULL: Accessor for Field l not found", "l IS NOT NULL: Accessor for Field l not found", "m IS NULL: Accessor for Field m not found", "m IS NOT NULL: Accessor for Field m not found", "s IS NULL: Accessor for Field s not found", "s IS NOT NULL: Accessor for Field s not found", ] ``` ### Describe the solution you'd like Build an accessor for every struct field, as iceberg-java does, so these predicates bind. `StructAccessor` holds a `PrimitiveType` today, so it would need to carry the field's `Type`. Binding alone would return wrong results in `ArrowReader`. I found this by reading the code and did not run it. The reader resolves predicate field ids through a map of Parquet leaf columns, and a Variant, list, map, or struct field id is not a leaf, so the reader would treat the column as missing from the file: - The Arrow row filter evaluates a missing column's `IS NOT NULL` as always false ([`predicate_visitor.rs`](https://github.com/apache/iceberg-rust/blob/30b5693461220ddd133619d1261b51823210ae2f/crates/iceberg/src/arrow/reader/predicate_visitor.rs#L618-L632)), so it would drop every row. - The page index evaluator skips every row for `IS NOT NULL` on a missing column ([`page_index_evaluator.rs`](https://github.com/apache/iceberg-rust/blob/30b5693461220ddd133619d1261b51823210ae2f/crates/iceberg/src/expr/visitors/page_index_evaluator.rs#L134-L143), [`not_null`](https://github.com/apache/iceberg-rust/blob/30b5693461220ddd133619d1261b51823210ae2f/crates/iceberg/src/expr/visitors/page_index_evaluator.rs#L645-L657)). So the change also needs these visitors to tell a non-primitive field apart from a missing column. The row filter could evaluate nullness on the projected group column. The page index evaluator, which has no statistics for a group, could select all rows. Tests that read a file through `ArrowReader` with these predicates would cover both. ### Willingness to contribute I cannot contribute to this feature at this time -- 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]
