Skip to content

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

Open
jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:fix/validation-portable-constructs-single-parse
Open

jbonofre wants to merge 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
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.

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.

2 participants