Skip to content

Apply PIVOT aliases before schema validation - #57

Merged
osipovartem merged 1 commit into
expr-planner-aggregate-schemafrom
snowflake-double-pivot-alias
Sep 3, 2026
Merged

Apply PIVOT aliases before schema validation#57
osipovartem merged 1 commit into
expr-planner-aggregate-schemafrom
snowflake-double-pivot-alias

Conversation

@osipovartem

Copy link
Copy Markdown
Collaborator

Which issue does this PR close?

Closes a Snowflake compatibility gap where chained PIVOT clauses produce duplicate intermediate literal column names before the outer table alias can rename them.

Rationale for this change

Snowflake supports assigning a complete column alias list to the result of chained PIVOT clauses. DataFusion currently builds the second aggregate first, rejects its duplicate output names, and never reaches apply_table_alias.

What changes are included in this PR?

  • normalize and apply explicit PIVOT output aliases while constructing group-by and aggregate expressions
  • preserve the existing alias-count validation and final table alias
  • add an integration test with two chained PIVOT clauses whose implicit literal names collide

Are there any user-facing changes?

Queries such as ... PIVOT(...) PIVOT(...) AS p(col1, col2, ...) now plan and execute when the explicit aliases make the final schema unambiguous.

How was this tested?

  • cargo +stable test -p datafusion-sql --lib --offline: 92 passed
  • cargo +stable test -p datafusion --test core_integration pivot_unpivot --offline: 3 passed
  • cargo +stable clippy -p datafusion-sql --all-targets --offline -- -D warnings
  • cargo +stable fmt --all --check

Stacked on #47, which contains the DF55 Snowflake compatibility patches.

@osipovartem
osipovartem merged commit e2413a5 into expr-planner-aggregate-schema Sep 3, 2026
69 checks passed
@osipovartem
osipovartem deleted the snowflake-double-pivot-alias branch September 3, 2026 06:03
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