feat(annotate_types): annotate ranking window functions with constant return types [CLAUDE]#7658
Merged
georgesittas merged 6 commits intoMay 20, 2026
Conversation
…eturn types [CLAUDE]
… return types [CLAUDE]
…strations [CLAUDE] Ranking window functions (DenseRank/Ntile/Rank/RowNumber → BIGINT, CumeDist/PercentRank → DOUBLE) are now provided by the base mapping in sqlglot/typing/__init__.py and match BigQuery's documented return types exactly. Removing them from the BigQuery override keeps the dialect file focused on entries that actually diverge from the base. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…LAUDE] PostgreSQL's NTILE returns integer while its other ranking window functions (RANK, DENSE_RANK, ROW_NUMBER) return bigint. Empirically verified via pg_typeof against PostgreSQL — matches the documented behavior in https://www.postgresql.org/docs/current/functions-window.html. Adds a new sqlglot/typing/postgres.py with the per-function override and wires it into the Postgres dialect. Redshift is unaffected — its NTILE returns BIGINT and it imports typing from the base, not from postgres. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per AWS Redshift docs, RANK() returns INTEGER while DENSE_RANK, NTILE, and ROW_NUMBER return BIGINT (the base default). CUME_DIST and PERCENT_RANK return FLOAT8 (DOUBLE, also base default). https://docs.aws.amazon.com/redshift/latest/dg/r_WF_RANK.html https://docs.aws.amazon.com/redshift/latest/dg/r_WF_DENSE_RANK.html Documentation-only — not empirically verified against a Redshift cluster. The asymmetry (RANK alone differing from the other three rank functions) is unusual; if a future verification shows the docs are wrong, the override is trivial to revisit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
georgesittas
added a commit
that referenced
this pull request
May 20, 2026
…t return types [CLAUDE] (#7658) * test(annotate_types): add failing tests for ranking window function return types [CLAUDE] * feat(annotate_types): annotate ranking window functions with constant return types [CLAUDE] * refactor(annotate_types): drop redundant BigQuery ranking window registrations [CLAUDE] Ranking window functions (DenseRank/Ntile/Rank/RowNumber → BIGINT, CumeDist/PercentRank → DOUBLE) are now provided by the base mapping in sqlglot/typing/__init__.py and match BigQuery's documented return types exactly. Removing them from the BigQuery override keeps the dialect file focused on entries that actually diverge from the base. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(annotate_types): override PostgreSQL NTILE return type to INT [CLAUDE] PostgreSQL's NTILE returns integer while its other ranking window functions (RANK, DENSE_RANK, ROW_NUMBER) return bigint. Empirically verified via pg_typeof against PostgreSQL — matches the documented behavior in https://www.postgresql.org/docs/current/functions-window.html. Adds a new sqlglot/typing/postgres.py with the per-function override and wires it into the Postgres dialect. Redshift is unaffected — its NTILE returns BIGINT and it imports typing from the base, not from postgres. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(annotate_types): override Redshift RANK return type to INT [CLAUDE] Per AWS Redshift docs, RANK() returns INTEGER while DENSE_RANK, NTILE, and ROW_NUMBER return BIGINT (the base default). CUME_DIST and PERCENT_RANK return FLOAT8 (DOUBLE, also base default). https://docs.aws.amazon.com/redshift/latest/dg/r_WF_RANK.html https://docs.aws.amazon.com/redshift/latest/dg/r_WF_DENSE_RANK.html Documentation-only — not empirically verified against a Redshift cluster. The asymmetry (RANK alone differing from the other three rank functions) is unusual; if a future verification shows the docs are wrong, the override is trivial to revisit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Jo <46752250+georgesittas@users.noreply.github.com>
Contributor
Author
Wonderful! |
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.
Replacing #7651.
The window functions
DENSE_RANK,NTILE,RANK, andROW_NUMBERalways return an integer rank with no inputs influencing the type.PERCENT_RANKandCUME_DISTalways return a value in [0, 1] and are always floating-point.Default (base dialect):
BIGINTfor the rank functions,DOUBLEfor the distribution functions. This matches PostgreSQL, SQL Server, Trino, Presto, Athena, and DuckDB.Hive, Spark, Databricks, and Snowflake return
INTEGER(32-bit) for the four rank functions. I verified this against the official documentation for each engine.