Skip to content

fix: sort InListExpr terms before building pruning predicate OR chain - #25311

Open
Rich-T-kid wants to merge 2 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/fix/sort-inlist-pruning-predicate
Open

Rich-T-kid wants to merge 2 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/fix/sort-inlist-pruning-predicate

Conversation

@Rich-T-kid

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • Closes n/a.

Rationale for this change

build_predicate_expression folds InListExpr values into an OR/AND chain in execution order, which is non-deterministic when the list is built from a hash join's build side. This makes the pruning predicate's string representation unstable between runs, causing flaky snapshot tests.

What changes are included in this PR?

In build_predicate_expression (datafusion/pruning/src/pruning_predicate.rs), IN-list items are sorted by display string before being folded into the OR/AND chain, making the output deterministic without changing pruning behavior.

What is the testing strategy for this PR?

I think this is straight forward enough to not warrant a test. can create one if anyone disagrees

Are there any user-facing changes?

somewhat. existing code doesnt break but moving forward users can expect deterministic formating

@codecov-commenter

codecov-commenter commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.92%. Comparing base (6bbd3f4) to head (7f40357).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main   #25311     +/-   ##
=========================================
  Coverage   81.91%   81.92%             
=========================================
  Files        1134     1135      +1     
  Lines      425708   427773   +2065     
  Branches   425708   427773   +2065     
=========================================
+ Hits       348726   350451   +1725     
- Misses      56305    56378     +73     
- Partials    20677    20944    +267     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

let change_expr = in_list
.list()
let mut sorted_list: Vec<_> = in_list.list().to_vec();
sorted_list.sort_by_key(|a| a.to_string());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The to_string part can be costly, is there a cheaper alternative maybe? Anyway the ordering doesn't really matter, anything stable that is cheaper would do, like hashing.

In case we want to keep it, we should probably be using sort_by_cached_key if the to_string part is finally expensive.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@asolimando updated this in the latest commit

@Rich-T-kid
Rich-T-kid force-pushed the rich-T-kid/fix/sort-inlist-pruning-predicate branch from 791592c to 7f40357 Compare September 15, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants