Skip to content

fix: Projection stats were Absent for columns referenced >1 time#22679

Open
neilconway wants to merge 1 commit into
apache:mainfrom
neilconway:neilc/fix-projection-stats
Open

fix: Projection stats were Absent for columns referenced >1 time#22679
neilconway wants to merge 1 commit into
apache:mainfrom
neilconway:neilc/fix-projection-stats

Conversation

@neilconway
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

ProjectionExprs::project_statistics uses std::mem::take to move an input column's ColumnStatistics into the output when given a direct column reference. This means if the column is referenced again (either directly or in a CAST expression), the statistics are Absent. The simple fix is to just clone instead of take.

This pattern crops up in TPC-DS q54, which includes a CTE that projects both d_date_sk and CAST(d_date_sk AS Float64), but it's a more general bug.

What changes are included in this PR?

  • Fix bug
  • Add unit tests

Are these changes tested?

Yes; new test added.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added the physical-expr Changes to the physical-expr crates label May 31, 2026
Copy link
Copy Markdown
Contributor

@Dandandan Dandandan left a comment

Choose a reason for hiding this comment

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

Nice find!

Copy link
Copy Markdown
Member

@asolimando asolimando left a comment

Choose a reason for hiding this comment

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

LGTM!


#[test]
fn test_project_statistics_column_and_cast() -> Result<()> {
// SELECT col0 AS num, CAST(col0 AS Int32) AS casted: the passthrough
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.

Nit: the comment is not too informative, maybe it can be dropped?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Projection stats Absent for columns referenced >1 time

3 participants