Skip to content

add support for ranking functions#252

Merged
JasonShin merged 2 commits intomainfrom
rank
Feb 8, 2026
Merged

add support for ranking functions#252
JasonShin merged 2 commits intomainfrom
rank

Conversation

@JasonShin
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 8, 2026 06:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the type inference for SQL window/ranking functions so generated TypeScript result types are more specific than any.

Changes:

  • Refines ranking/window function result fields from any to number in demo query typings (e.g., ROW_NUMBER, RANK, DENSE_RANK, NTILE).
  • Treats several window value functions as type-polymorphic in the SQL parser (e.g., LAG, LEAD, FIRST_VALUE).
  • Updates snapshot typings to match the new inferred result types.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/demo/window/row_number.snapshot.ts Updates rowNum to number in snapshots to reflect new typing.
tests/demo/window/row_number.queries.ts Updates rowNum to number in query typings.
tests/demo/window/rank_functions.snapshot.ts Updates ranking-related fields (rank, denseRank, quartile, rowNum) to number in snapshots.
tests/demo/window/rank_functions.queries.ts Updates ranking-related fields to number in query typings.
tests/demo/window/lag_lead.snapshot.ts Updates window value fields (previousName, nextName, etc.) from any to string in snapshots.
tests/demo/window/lag_lead.queries.ts Updates window value fields from any to string in query typings.
tests/demo/cte/cte.snapshot.ts Updates rk (rank) field from any to number in snapshot.
tests/demo/cte/cte.queries.ts Updates rk (rank) field from any to number in query typings.
src/ts_generator/sql_parser/expressions/functions.rs Classifies ranking functions as numeric and value window functions as type-polymorphic.
Comments suppressed due to low confidence (6)

tests/demo/window/lag_lead.queries.ts:1

  • LAG/LEAD (and often NTH_VALUE) can return NULL when the requested row is out of range (e.g., LAG on the first row, LEAD on the last row) unless the SQL uses a default value. Typing these fields as string is likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type for LAG/LEAD (and NTH_VALUE, if supported) to include nullability (e.g., string | null here), or adjust the demo queries/tests to explicitly filter out rows where these values are NULL if you intentionally want a non-null string type.
    tests/demo/window/lag_lead.queries.ts:1
  • LAG/LEAD (and often NTH_VALUE) can return NULL when the requested row is out of range (e.g., LAG on the first row, LEAD on the last row) unless the SQL uses a default value. Typing these fields as string is likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type for LAG/LEAD (and NTH_VALUE, if supported) to include nullability (e.g., string | null here), or adjust the demo queries/tests to explicitly filter out rows where these values are NULL if you intentionally want a non-null string type.
    tests/demo/window/lag_lead.queries.ts:1
  • LAG/LEAD (and often NTH_VALUE) can return NULL when the requested row is out of range (e.g., LAG on the first row, LEAD on the last row) unless the SQL uses a default value. Typing these fields as string is likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type for LAG/LEAD (and NTH_VALUE, if supported) to include nullability (e.g., string | null here), or adjust the demo queries/tests to explicitly filter out rows where these values are NULL if you intentionally want a non-null string type.
    tests/demo/window/lag_lead.queries.ts:1
  • LAG/LEAD (and often NTH_VALUE) can return NULL when the requested row is out of range (e.g., LAG on the first row, LEAD on the last row) unless the SQL uses a default value. Typing these fields as string is likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type for LAG/LEAD (and NTH_VALUE, if supported) to include nullability (e.g., string | null here), or adjust the demo queries/tests to explicitly filter out rows where these values are NULL if you intentionally want a non-null string type.
    tests/demo/window/lag_lead.queries.ts:1
  • LAG/LEAD (and often NTH_VALUE) can return NULL when the requested row is out of range (e.g., LAG on the first row, LEAD on the last row) unless the SQL uses a default value. Typing these fields as string is likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type for LAG/LEAD (and NTH_VALUE, if supported) to include nullability (e.g., string | null here), or adjust the demo queries/tests to explicitly filter out rows where these values are NULL if you intentionally want a non-null string type.
    tests/demo/window/lag_lead.queries.ts:1
  • LAG/LEAD (and often NTH_VALUE) can return NULL when the requested row is out of range (e.g., LAG on the first row, LEAD on the last row) unless the SQL uses a default value. Typing these fields as string is likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type for LAG/LEAD (and NTH_VALUE, if supported) to include nullability (e.g., string | null here), or adjust the demo queries/tests to explicitly filter out rows where these values are NULL if you intentionally want a non-null string type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JasonShin JasonShin merged commit 94b35df into main Feb 8, 2026
33 checks passed
@JasonShin JasonShin deleted the rank branch February 8, 2026 06:34
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.

1 participant