fix: handle Annotated nodes in lineage column resolution#73
Open
eitsupi wants to merge 1 commit intotobilg:mainfrom
Open
fix: handle Annotated nodes in lineage column resolution#73eitsupi wants to merge 1 commit intotobilg:mainfrom
eitsupi wants to merge 1 commit intotobilg:mainfrom
Conversation
When a SQL comment appears between SELECT and the first column (e.g. `SELECT\n-- comment\na FROM t`), the parser wraps the column expression in an Annotated node. The `get_alias_or_name` function did not handle this variant, causing `find_select_expr` to fail with "Cannot find column" errors. Add an Annotated arm to `get_alias_or_name` that unwraps to the inner expression. This is consistent with `find_column_refs_in_expr` which already handles Annotated nodes. Add tests for line comments, block comments, aliased columns with comments, and multi-column queries with leading comments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
get_alias_or_name()to unwrapAnnotatedexpression nodes, which are produced when SQL comments appear betweenSELECTand the first columnDetails
When the parser encounters a comment before a SELECT expression, it wraps the expression in an
Annotatednode to preserve the comment. Theget_alias_or_name()function in the lineage module only matchedAlias,Column,Identifier, andStarvariants — it did not handleAnnotated, returningNoneand causingfind_select_expr()to fail.The fix adds a single recursive arm for
Expression::Annotated(a) => get_alias_or_name(&a.this), consistent with howfind_column_refs_in_expralready handlesAnnotatednodes elsewhere in the same file.Test plan
test_node_name_doesnt_contain_comment(requires derived table star expansion, separate issue)🤖 Generated with Claude Code