Skip to content

Preserve aggregate field metadata when folding exact statistics - #194

Merged
osipovartem merged 1 commit into
fix/schema-modifiers-parser-pin-20261113from
fix/aggregate-statistics-field-metadata-20261126
Nov 25, 2026
Merged

osipovartem merged 1 commit into
fix/schema-modifiers-parser-pin-20261113from
fix/aggregate-statistics-field-metadata-20261126

Conversation

@osipovartem

@osipovartem osipovartem commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Why

AggregateStatistics can replace a COUNT with a constant from exact source statistics, but constructing the replacement as a metadata-free literal drops the aggregate result field's metadata. A metadata-aware outer projection then needs a separate node to restore the declaration.

Change

  • Carry the original output field's metadata on the replacement physical literal, not on a separate projection. Keep the existing literal constructor for outputs with no metadata.
  • Add a regression for both single-phase and partial/final COUNT plans. It checks that the statistics optimization still produces a projection and the expected native value, and that the result field keeps its metadata.

Verification

  • The exact new regression body failed against the retained baseline (missing field metadata) and passed with the modified production rule linked to the cached matching DataFusion dependencies.
  • An additional eight-query native comparison with tagged COUNT verified identical native arrays and the same preorder sequence of physical operators, including the statistics fast path.
  • A separate three-column red/green probe verified output ordinals, an untagged column, and distinct partial vs final declarations, with native values [3, 2, 1]. The baseline drops both tags; the candidate restores only the two final tags in both Single and Partial/Final plans.
  • Rustfmt and git diff --check pass. Independent read-only review approved the exact commit subject to green CI on that head and an unchanged base.

All 38 hosted checks passed on b578f510, including the SQLite SQLLogicTest suite. The accepted merge commit 450e7e90 has the same source tree.

This change is generic DataFusion metadata preservation; it does not register a Snowflake-specific COUNT implementation in Rustice.

@osipovartem
osipovartem marked this pull request as ready for review November 25, 2026 22:51
@osipovartem
osipovartem merged commit 450e7e9 into fix/schema-modifiers-parser-pin-20261113 Nov 25, 2026
38 checks passed
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.

1 participant