Skip to content

feat(duckdb): Fix and updates tests for pivot subquery string lietral column names#7757

Merged
georgesittas merged 2 commits into
mainfrom
RD-1205936-transpile-bug-pivot-subquery-string-literal-column-names
Jun 18, 2026
Merged

feat(duckdb): Fix and updates tests for pivot subquery string lietral column names#7757
georgesittas merged 2 commits into
mainfrom
RD-1205936-transpile-bug-pivot-subquery-string-literal-column-names

Conversation

@fivetran-amrutabhimsenayachit

@fivetran-amrutabhimsenayachit fivetran-amrutabhimsenayachit commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Problem

Transpiling a Snowflake PIVOT query with string literal IN-values (e.g. IN ('JAN', 'FEB')) on a subquery source failed in DuckDB with zero-length delimited identifier after the optimizer ran.

Two compounding root causes:

The Snowflake parser stored pivot column names with surrounding apostrophes ('JAN' stored as identifier "'JAN'"), because it used fld.sql() instead of fld.alias_or_name. This propagated through qualify_columns star-expansion into column references like ""."'JAN'" — the 'JAN' part was invalid, and the "" empty table qualifier (cause #2) was also rejected.

When the pivot sat on a subquery with no alias, pivot.alias was '', so exp.column(name, table='') generated a zero-length delimited identifier "" as the table qualifier, which DuckDB rejects outright.

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

SQLGlot Integration Test Results

✅ All tests passed

Comparing:

  • this branch (sqlglot:RD-1205936-transpile-bug-pivot-subquery-string-literal-column-names @ sqlglot a199021)
  • baseline (main @ sqlglot 6f99d4e)

Overall

main: 192441 total, 153536 passed (pass rate: 79.8%)

sqlglot:RD-1205936-transpile-bug-pivot-subquery-string-literal-column-names: 180247 total, 142391 passed (pass rate: 79.0%)

Transitions:
No change

Dialect pair changes: 0 previous results not found, 3 current results not found

✅ All tests passed

@fivetran-amrutabhimsenayachit fivetran-amrutabhimsenayachit force-pushed the RD-1205936-transpile-bug-pivot-subquery-string-literal-column-names branch 2 times, most recently from 302d2dd to 9f87c68 Compare June 17, 2026 15:13
@georgesittas

Copy link
Copy Markdown
Collaborator

@fivetran-amrutabhimsenayachit did you check the test failures?

@fivetran-amrutabhimsenayachit fivetran-amrutabhimsenayachit force-pushed the RD-1205936-transpile-bug-pivot-subquery-string-literal-column-names branch from 9f87c68 to c8d4222 Compare June 17, 2026 18:14
Comment thread sqlglot/optimizer/qualify_columns.py
@georgesittas georgesittas merged commit 72e6796 into main Jun 18, 2026
8 checks passed
@georgesittas georgesittas deleted the RD-1205936-transpile-bug-pivot-subquery-string-literal-column-names branch June 18, 2026 08:49
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.

2 participants