Skip to content

fix(validation): reject an Alias root in every dialect - #781

Open
iprithv wants to merge 1 commit into
apache:mainfrom
iprithv:fix/validation-reject-alias-root
Open

iprithv wants to merge 1 commit into
apache:mainfrom
iprithv:fix/validation-reject-alias-root

Conversation

@iprithv

@iprithv iprithv commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

sqlglot parses a missing operator (price quantity) and a trailing AS as an Alias. _parse_sql_expression returned that tree as success, so the wrap/quote fallbacks that already refuse an Alias never ran. no_such_field in SUM(price) no_such_field sat in the alias slot, so name checks never saw it.

#777 already fails those shapes for portable sql:. An ANSI_SQL or vendor dialect entry with the same text still printed Validation PASSED. This rejects an Alias root on the parse success path in every dialect, matching the fallbacks. CAST(x AS t) is Cast and stays valid. parse_tree is then None, so scope leaves the error to the SQL check.

Follow-up leftover after #777. #779 moves the portable construct walk into parse; it still leaves vendor dialects alone.

Reject an Alias root from _parse_sql_expression in every dialect, so juxtaposition and a trailing AS fail SQL validation (and parse_tree is None) instead of passing as a named expression.

Related

Leftover from #777. No open issue.

sqlglot parses juxtaposition (`price quantity`) and a trailing AS as an
Alias. The wrap and first-token-quoted fallbacks already refuse that
shape, but a successful bare parse still returned the tree, so an
ANSI_SQL or vendor dialect entry printed Validation PASSED and
parse_tree handed name checks a tree whose alias identifier was never a
column.

Reject an Alias root on that success path, in every dialect. CAST(x AS t)
is Cast and stays valid. parse_tree is then None, so scope leaves the
error to the SQL check.

Signed-off-by: Prithvi S <prithvisivasankar@gmail.com>

@vigneshio vigneshio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR covers what #777 left open: the Alias-root check on the bare parse success path. Wrap and quote-retry already reject that shape in every dialect, parse_tree going None keeps no_such_field out of scope, and CAST(x AS t) still parses as a Cast. INTERVAL stays a vendor form.

I added one related case to the new parametrize list, a IS, and kept a IS NULL as valid next to CAST.

#779 still composes with this, so I don't think this PR needs to wait on it.

CC: @jbonofre

"SUM(price) no_such_field",
"SUM(orders.price) AS total",
"a b",
"a AS b",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a IS is the same Alias root (a AS IS) as a b, and #777 already pins it for OSSIE_SQL_2026. Adding it to this list, and a IS NULL next to the CAST case so that cousin stays accepted in ANSI_SQL, would cover the IS pair the way juxtaposition is covered here.

@jbonofre
jbonofre self-requested a review November 21, 2026 09:50

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Rejecting an exp.Alias root on the bare parse_one success path in _parse_sql_expression aligns all dialects with the wrap/quote fallbacks and ensures parse_tree returns None so downstream checks don't inspect an alias tree.

@jbonofre

Copy link
Copy Markdown
Member

I opened #782 to fix the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants