Skip to content

feat(annotate_types): propagate type through Lag/Lead/NthValue window functions [CLAUDE]#7652

Open
RichardHughes-amp wants to merge 1 commit into
tobymao:mainfrom
RichardHughes-amp:register-offset-window-typing
Open

feat(annotate_types): propagate type through Lag/Lead/NthValue window functions [CLAUDE]#7652
RichardHughes-amp wants to merge 1 commit into
tobymao:mainfrom
RichardHughes-amp:register-offset-window-typing

Conversation

@RichardHughes-amp
Copy link
Copy Markdown
Contributor

@RichardHughes-amp RichardHughes-amp commented May 16, 2026

What it says on the tin. Lag/Lead/NthValue can only propagate type from the column they're selecting from.

… functions

Registers Lag, Lead, and NthValue in the base EXPRESSION_METADATA with an
_annotate_by_args(e, "this") annotator so that the return type follows the
type of the first argument. Previously these resolved to UNKNOWN.

Note: the 3-arg LAG/LEAD(col, offset, default) form could in principle widen
the result type to the common type of col and default; that is deferred to a
follow-up. Propagating "this" is strictly correct for the common cases
(default omitted, or default is a NULL/compatible literal). [CLAUDE]

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@RichardHughes-amp RichardHughes-amp force-pushed the register-offset-window-typing branch from 64acdfb to b7a366f Compare May 16, 2026 01:19
@RichardHughes-amp RichardHughes-amp marked this pull request as ready for review May 16, 2026 01:28
Copy link
Copy Markdown
Collaborator

@VaggelisD VaggelisD left a comment

Choose a reason for hiding this comment

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

Thank you for the PR once again @RichardHughes-amp! Leaving a few comments

exp.HavingMax,
exp.Lag,
exp.LastValue,
exp.Lead,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we remove exp.Lead from bigquery's typing? it's also on "this" so its redundant

exp.Filter,
exp.FirstValue,
exp.HavingMax,
exp.Lag,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

BigQuery's exp.Lag typing is also based on default, could that true for more dialects?

exp.LastValue,
exp.Lead,
exp.Limit,
exp.NthValue,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Similar to exp.Lead, we can remove the BQ entry

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