Conversation
Contributor
There was a problem hiding this comment.
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
anytonumberin 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 oftenNTH_VALUE) can returnNULLwhen the requested row is out of range (e.g.,LAGon the first row,LEADon the last row) unless the SQL uses a default value. Typing these fields asstringis likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type forLAG/LEAD(andNTH_VALUE, if supported) to include nullability (e.g.,string | nullhere), or adjust the demo queries/tests to explicitly filter out rows where these values areNULLif you intentionally want a non-nullstringtype.
tests/demo/window/lag_lead.queries.ts:1LAG/LEAD(and oftenNTH_VALUE) can returnNULLwhen the requested row is out of range (e.g.,LAGon the first row,LEADon the last row) unless the SQL uses a default value. Typing these fields asstringis likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type forLAG/LEAD(andNTH_VALUE, if supported) to include nullability (e.g.,string | nullhere), or adjust the demo queries/tests to explicitly filter out rows where these values areNULLif you intentionally want a non-nullstringtype.
tests/demo/window/lag_lead.queries.ts:1LAG/LEAD(and oftenNTH_VALUE) can returnNULLwhen the requested row is out of range (e.g.,LAGon the first row,LEADon the last row) unless the SQL uses a default value. Typing these fields asstringis likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type forLAG/LEAD(andNTH_VALUE, if supported) to include nullability (e.g.,string | nullhere), or adjust the demo queries/tests to explicitly filter out rows where these values areNULLif you intentionally want a non-nullstringtype.
tests/demo/window/lag_lead.queries.ts:1LAG/LEAD(and oftenNTH_VALUE) can returnNULLwhen the requested row is out of range (e.g.,LAGon the first row,LEADon the last row) unless the SQL uses a default value. Typing these fields asstringis likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type forLAG/LEAD(andNTH_VALUE, if supported) to include nullability (e.g.,string | nullhere), or adjust the demo queries/tests to explicitly filter out rows where these values areNULLif you intentionally want a non-nullstringtype.
tests/demo/window/lag_lead.queries.ts:1LAG/LEAD(and oftenNTH_VALUE) can returnNULLwhen the requested row is out of range (e.g.,LAGon the first row,LEADon the last row) unless the SQL uses a default value. Typing these fields asstringis likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type forLAG/LEAD(andNTH_VALUE, if supported) to include nullability (e.g.,string | nullhere), or adjust the demo queries/tests to explicitly filter out rows where these values areNULLif you intentionally want a non-nullstringtype.
tests/demo/window/lag_lead.queries.ts:1LAG/LEAD(and oftenNTH_VALUE) can returnNULLwhen the requested row is out of range (e.g.,LAGon the first row,LEADon the last row) unless the SQL uses a default value. Typing these fields asstringis likely incorrect for the general case and can break consumers at runtime. Suggest changing the inferred return type forLAG/LEAD(andNTH_VALUE, if supported) to include nullability (e.g.,string | nullhere), or adjust the demo queries/tests to explicitly filter out rows where these values areNULLif you intentionally want a non-nullstringtype.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.