Repository navigation
fix(semantics): check a named window's keys as column references - #262
Merged
Merged
Conversation
A SELECT's clause check read its joins, filters, groups and orders but never a WINDOW clause, so an unknown column in a named window's PARTITION BY or ORDER BY went unreported in every dialect, both in SELECT ... WINDOW and in a WINDOW written after a parenthesized query. The keys of each named window are now checked at the level an inline OVER in a projection reads: output aliases in the dialects that read them anywhere, input columns only in the others. PostgreSQL, which follows SQL99 rules for a window definition, so refuses an output alias there. Databricks and PostgreSQL cases cover unknown partition and order keys, a window after the parentheses and an output alias.
The previous change checked the keys of every named window, so a window nothing used reported E201 or E222 for a key that is never resolved. DuckDB, SQLite and Databricks accept such a query, and Spark never resolves an unused window. A named window's keys are now checked only when an OVER in the query or in an ORDER BY after it names the window, directly or through a window that extends it. This holds in every dialect, so PostgreSQL's and ClickHouse's refusal of an unused bad window is not reported. DuckDB cases cover unused windows with unknown keys, qualifiers and a subquery, a used window, a window reached through another, and a key that reads an output alias. The previous commit's message said its Databricks cases covered an output alias; only the PostgreSQL ones do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A named window's PARTITION BY and ORDER BY keys were never resolved, so
SELECT sum(b) OVER w FROM t WINDOW w AS (ORDER BY nope)reported nothing, while the same key written inline in OVER gave E201.Changes
WINDOW, for a SELECT and for a subquery, resolve as column references in the scope an inline window would see, in every dialect: unknown columns give E201 and unknown qualifiers E222.Verification
make check-cion the final head.