Skip to content

fix: evaluate shared volatile struct fields once on branch-55 - #196

Merged
bvolpato-dd merged 3 commits into
branch-55from
bv/cherry-pick-datafusion-24720
Nov 20, 2026
Merged

bvolpato-dd merged 3 commits into
branch-55from
bv/cherry-pick-datafusion-24720

Conversation

@bvolpato-dd

@bvolpato-dd bvolpato-dd commented Nov 3, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Backports the fix for inconsistent reads of volatile struct fields to branch-55. Upstream issue, upstream fix

Rationale for this change

On branch-55, selecting both a struct containing random() and a field from that struct can produce two different values for the same field. A filter can also return rows that fail its own predicate.

Repeated evaluation can add cost for a model-backed UDF. In a 20-row query that sorts its input, keeps two rows and reads two struct fields, the UDF processed 40 rows on the base and two with the fix. Both returned 20 and 19. A monthly savings estimate would require production query volume and cost per row.

What changes are included in this PR?

Projection merging keeps one evaluation for each shared volatile value, including after physical optimization. Separately written calls remain independent. Keeping the defining projection can limit column pruning in affected plans. File metadata expressions can still reach their Parquet scans when a sibling field reads a volatile value.

A separate test-only commit switches the CLI S3 fixture to RustFS. The pinned MinIO image returns HTTP 404 on the current base. Failing base job

Are these changes tested?

SQL regressions cover struct and filter agreement, joins, nested projections, and Parquet row indices across a limit and a union. A counter UDF checks that physical optimization preserves a shared result.

Are there any user-facing changes?

A projected field and a filter now read the same value as the returned struct.

This backport was prepared with AI assistance. If maintaining it on branch-55 is not worth the benefit, please close the PR with a brief rationale.

@codecov-commenter

codecov-commenter commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.13043% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.23%. Comparing base (e7af2a2) to head (dc7d083).

Files with missing lines Patch % Lines
...tafusion/optimizer/src/extract_leaf_expressions.rs 88.37% 4 Missing and 21 partials ⚠️
...tafusion/optimizer/src/optimize_projections/mod.rs 83.33% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           branch-55     #196    +/-   ##
===========================================
  Coverage      81.22%   81.23%            
===========================================
  Files           1111     1111            
  Lines         389078   389273   +195     
  Branches      389078   389273   +195     
===========================================
+ Hits          316046   316226   +180     
+ Misses         54358    54356     -2     
- Partials       18674    18691    +17     

☔ 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.

@bvolpato-dd
bvolpato-dd marked this pull request as ready for review November 5, 2026 03:50
@bvolpato-dd bvolpato-dd changed the title Cherry-pick apache/datafusion#24720 fix: preserve volatile struct fields on branch-55 Nov 5, 2026
@bvolpato-dd
bvolpato-dd requested a review from gabotechs November 9, 2026 19:50
@bvolpato-dd bvolpato-dd changed the title fix: preserve volatile struct fields on branch-55 fix: evaluate shared volatile struct fields once on branch-55 Nov 16, 2026
jaideeppyne and others added 3 commits November 16, 2026 14:07
…ssions (apache#24720)

Keep an extraction above a projection when inlining the source expression
would evaluate a volatile value twice. Cover projected fields and filter
predicates that read the same struct.

(cherry picked from commit 27e81e9)
Count references to the same output field before merging logical or
physical projections. Keep independent volatile calls separate and let
file metadata expressions reach their scans across a limit or union.

Exercise the affected paths with a counter UDF, struct comparisons and
Parquet row indices.
The pinned MinIO image returns HTTP 404 on branch-55. Start RustFS and
upload the existing fixtures so CI can exercise the same CLI queries.
@bvolpato-dd
bvolpato-dd force-pushed the bv/cherry-pick-datafusion-24720 branch from 65ca6fe to dc7d083 Compare November 16, 2026 14:07
@bvolpato-dd

Copy link
Copy Markdown
Author

@gabotechs, the backport is ready for review on branch-55. The first commit preserves the upstream fix. The second covers the fork's logical and physical projection rewrites, including keeping file_row_index() at its Parquet scan when a sibling reads a volatile field. The last commit changes only the CLI S3 fixture and its documentation. Commits

I reproduced both wrong results on the current base. A field disagreed with its struct, and some returned rows failed their filter. Both queries returned the expected result after the rebase. In the top-two query, both versions returned 20 and 19, while the counted UDF processed 40 rows on the base and two on this branch.

The extended workspace suite, RustFS-backed CLI tests, and lint passed locally. Criterion reported no regression in the projection benchmarks against branch-55. GitHub CI passed on dc7d083. The branch is mergeable and has no open review threads. CI results

@bvolpato-dd
bvolpato-dd merged commit 5bc24de into branch-55 Nov 20, 2026
70 checks passed
@bvolpato-dd
bvolpato-dd deleted the bv/cherry-pick-datafusion-24720 branch November 20, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants