Skip to content

fix(validation): reject portable constructs in _parse_sql_expression and skip SELECT DISTINCT - #779

Merged
christianeu-db merged 1 commit into
apache:mainfrom
jbonofre:fix/validation-portable-constructs-single-parse
Nov 26, 2026
Merged

christianeu-db merged 1 commit into
apache:mainfrom
jbonofre:fix/validation-portable-constructs-single-parse

Conversation

@jbonofre

Copy link
Copy Markdown
Member

Follow-up to #777:

  • Move _portable_sql_construct_error from validate_sql_expression into _parse_sql_expression so parse_tree and downstream checks (validate_metric_scoping, validate_metric_agreement, validate_metric_references, validate_field_shadowing, validate_agg_placement) treat rejected OSSIE_SQL_2026 expressions as unparsed instead of emitting secondary [Scope]/[Drift] diagnostics. This restores _parse_sql_expression's single-parse contract and aligns with feat(validation): reject queries in portable expressions and parse query sources #698.
  • Skip exp.Distinct nodes whose parent is exp.Select so SELECT DISTINCT ... stays deferred alongside SELECT ... rather than reporting "DISTINCT requires an argument".

Testing

  • uv run validation/test_validate.py (59 tests passed)
  • uv run --with pytest --with pyyaml --with jsonschema --with sqlglot -m pytest validation/tests/ (966 passed, 1 skipped)
  • uv run validation/validate.py examples/tpcds_semantic_model.yaml
  • uv run validation/validate.py examples/renamed_fields.yaml

Comment thread validation/validate.py Outdated
return None

interval_cls = getattr(exp, "Interval", None)
if interval_cls is not None and next(tree.find_all(interval_cls), None) is not None:

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.

This also catches a field named interval. sqlglot reads interval + grace as an INTERVAL literal, so a model with fields interval and grace and a third one defined as sql: interval + grace passed before #777 and now fails with "INTERVAL is not part of OSSIE_SQL_2026". The grammar takes interval as a plain name, and grace + interval or "interval" + grace pass.

christianeu-db
christianeu-db previously approved these changes Nov 23, 2026

@christianeu-db christianeu-db 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.

LGTM @jbonofre , thanks! +1 to @kayemkim's point on a field named interval (fine here or as a follow-up), and one nit inline.

Comment thread validation/validate.py
return None, count_error
return wrapped, None

def accept(node: object) -> tuple[object | None, str | None]:

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.

nit: _parse_sql_expression now also returns (None, error) for the rejected OSSIE_SQL_2026 constructs, but its docstring still lists only syntax, empty, multi-statement and non-expression statement errors. Could we add them there, since the downstream checks now rely on it?

@christianeu-db christianeu-db 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.

@jbonofre there are some new merge conflicts but otherwise looks good to merge

@jbonofre
jbonofre force-pushed the fix/validation-portable-constructs-single-parse branch from e2a5ada to 5bb5e91 Compare November 26, 2026 08:07
@jbonofre

Copy link
Copy Markdown
Member Author

@christianeu-db I rebased and resolved the conflicts. If you can approve again, that would be great 😄 Thanks!

@christianeu-db
christianeu-db merged commit c298049 into apache:main Nov 26, 2026
9 checks passed
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