Repository navigation
feat: push down struct IS NULL and IS NOT NULL into the Parquet scan - #25633
amitvijapur wants to merge 3 commits into
Conversation
A null check on a whole struct column was rejected by the row filter pushdown checker, so it stayed in a FilterExec that materialised every leaf of the struct. The check needs only the struct's null bitmap, which the Parquet decoder rebuilds from the definition levels of any projected leaf, so record it as an access to the struct's first leaf and let the existing get_field read plan select that one leaf. Closes apache#21795
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25633 +/- ##
========================================
Coverage 82.49% 82.49%
========================================
Files 1140 1140
Lines 438855 439018 +163
Branches 438855 439018 +163
========================================
+ Hits 362024 362189 +165
+ Misses 54958 54956 -2
Partials 21873 21873 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| /// The field path from a Struct down to its first non-Struct child, or `None` | ||
| /// when `data_type` is not a Struct or no child has a leaf. | ||
| fn first_leaf_path(data_type: &DataType) -> Option<Vec<String>> { |
There was a problem hiding this comment.
The function name is misleading. As the docstring says it returns the path to the first non-struct field. It is not necessary to be a leaf - it could be a List, Map, Union, ...
| fields.iter().find_map(|field| { | ||
| let mut path = vec![field.name().clone()]; | ||
| if matches!(field.data_type(), DataType::Struct(_)) { | ||
| path.extend(first_leaf_path(field.data_type())?); | ||
| } | ||
| Some(path) | ||
| }) |
There was a problem hiding this comment.
This could be optimized by checking first the primitive types:
| fields.iter().find_map(|field| { | |
| let mut path = vec![field.name().clone()]; | |
| if matches!(field.data_type(), DataType::Struct(_)) { | |
| path.extend(first_leaf_path(field.data_type())?); | |
| } | |
| Some(path) | |
| }) | |
| fields | |
| .iter() | |
| .filter(|field| !field.data_type().is_nested()) | |
| .chain( | |
| fields | |
| .iter() | |
| .filter(|field| field.data_type().is_nested()), | |
| ) | |
| .find_map(|field| { | |
| let mut path = vec![field.name().clone()]; | |
| if matches!(field.data_type(), DataType::Struct(_)) { | |
| path.extend(first_leaf_path(field.data_type())?); | |
| } | |
| Some(path) | |
| }) |
| } | ||
|
|
||
| #[test] | ||
| fn first_leaf_path_descends_to_the_first_primitive() { |
There was a problem hiding this comment.
| fn first_leaf_path_descends_to_the_first_primitive() { | |
| fn first_leaf_path_prefers_scalar_leaves() { |
| assert_eq!( | ||
| first_leaf_path(&list_first), | ||
| Some(vec!["items".to_string()]) | ||
| ); |
There was a problem hiding this comment.
| ); | |
| ); | |
| let list_before_scalar = DataType::Struct( | |
| vec![ | |
| Arc::new(Field::new_list( | |
| "items", | |
| Field::new("item", DataType::Int32, true), | |
| true, | |
| )), | |
| Arc::new(Field::new("tag", DataType::Utf8, true)), | |
| ] | |
| .into(), | |
| ); | |
| assert_eq!( | |
| first_leaf_path(&list_before_scalar), | |
| Some(vec!["tag".to_string()]) | |
| ); |
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
Which issue does this PR close?
Rationale for this change
WHERE struct_col IS NOT NULLcannot be pushed into the Parquet scan today:PushdownCheckerrejects any filter that references a whole struct column, so the check stays in aFilterExecabove the scan and every leaf of the struct is decoded just to read its null bitmap. #20822 and #20854 added pushdown forget_fieldon struct fields; the null check on the struct itself was left out.What changes are included in this PR?
The checker now recognises
IS NULL/IS NOT NULLwhose argument is aColumnof struct type and records it as aStructFieldAccessto a non-Struct descendant, preferring a non-nested field at each level. The existingget_fieldread plan projects that field. When it is scalar, one Parquet leaf is read; when only nested children are available, the selected field can have more than one leaf. Those leaves carry the enclosing struct's definition levels, so the decoder rebuilds the struct's null bitmap. Other whole-struct references (for examples = s) are still rejected.One consequence to be aware of: once the predicate reaches
DataSourceExec, a row group pruning predicates_null_count != row_countis built for it. That would be wrong if a struct's null count were taken from a child leaf's statistics, because a non-null struct with a null child field counts toward the leaf. It is not: struct statistics are reported as unknown, and the slt below pins the case where a whole row group has non-null structs with a null first leaf.Are these changes tested?
Unit tests cover both checks being pushable, a whole-struct reference (
struct_col = struct_col) still being rejected, the projection mask selecting exactly one of a struct's three leaves, andfirst_non_struct_field_pathfor nested, list-child, scalar-priority, empty-child and non-struct inputs.parquet_filter_pushdown.sltcovers theEXPLAIN, both null checks, a null check combined with a field predicate, and the two-row-group pruning case. On the current branch,cargo test -p datafusion-datasource-parquet(267 unit tests and doctests),cargo test --test sqllogictests -- parquet_filter_pushdown.slt, andcargo clippy --all-targets --all-features -- -D warningspass locally.Are there any user-facing changes?
No API change. A null check on a struct column is now evaluated during Parquet decoding and projects a descendant field rather than the whole struct. It reads one leaf when a scalar child is available.
The initial implementation used Claude Code assistance. The review follow-up used Codex assistance; the tests and lint listed above were run locally.