Skip to content

feat(grammar): address PR #657 review follow-ups - #719

Open
jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:feat/grammar-followups
Open

jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:feat/grammar-followups

Conversation

@jbonofre

Copy link
Copy Markdown
Member

Summary

Addresses the non-blocking review comments and tooling follow-ups from #657:

  • || precedence & documentation: Parse || (# concatValue) below + and - (# additiveValue) so a || b + c parses as a || (b + c), matching sqlglot (validation/validate.py) and PostgreSQL. Clarify in core-spec/grammar/README.md that || is a REQUIRED operator in expression_language.md whose precedence is not yet stated in the spec.
  • ORDER in nonReservedWord: Allow ORDER as an unquoted identifier so the portable example in core-spec/spec.md (SUM(order.sales) / COUNT(DISTINCT order.customer_id)) parses cleanly, and pin it alongside EXISTS_IN() in compliance/expressions/valid.txt.
  • Precedence & compliance model tests:
    • Add test_unary_binds_tighter_than_multiplication_and_addition and test_addition_binds_tighter_than_concat in core-spec/grammar/tests/test_expression_grammar.py.
    • Add test_compliance_models_parse to parse all portable expressions in compliance/**/*.ossie.yaml (and trigger Grammar CI when compliance/**/*.ossie.yaml changes).
  • Tooling alignment with Infra: Add Makefile support to Apache Ossie #682:
    • Consolidate core-spec/grammar/ruff.toml into the root ruff.toml and format core-spec/grammar/tests/conftest.py accordingly.
    • Add missing trailing newline to .editorconfig.
    • Add make test-grammar target and include core-spec/grammar in make clean.
    • Align astral-sh/setup-uv in .github/workflows/grammar-ci.yml to v10.3.3.

Related Issues

Follow-up to #657.

Checklist

Specification

  • Spec changes are included in core-spec/ and follow the existing structure
  • Spec changes have been discussed on the mailing list or in a linked issue
  • Breaking changes to the spec are clearly called out in the summary
  • For a material spec change, docs/spec_changes.md records rationale, compatibility and migration impact, or the PR explains why no entry is needed (reference grammar follow-up only; no normative spec change)

Ontology

  • Ontology changes in ontology/ are consistent with spec changes
  • New or modified terms are defined and documented

Converters

Validation

  • Validation rules in validation/ are updated if the spec changed
  • New validation cases are covered by tests

Documentation

  • docs/ is updated to reflect any user-facing changes
  • New features or behaviors are documented with examples where appropriate
  • CONTRIBUTING.md is updated if the contribution process changed

Examples

  • examples/ are added or updated for any new spec constructs

Tests

  • All existing tests pass (pytest / CI green)
  • New functionality is covered by tests

Compliance

  • ASF license headers are present on all new source files
  • No third-party dependencies are added without PMC/IPMC approval
  • If third-party source code is vendored/copied (not just declared as a dependency), NOTICE and/or LICENSE have been updated per ASF policy

Align || precedence below + and - to match sqlglot and PostgreSQL, allow ORDER as a non-reserved identifier, add unary and concat precedence tests, parse compliance/**/*.ossie.yaml models, and consolidate grammar Ruff and Makefile configuration with apache#682.

@orca-review-bot orca-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me. make test-grammar passes locally (12 passed). The || move matches sqlglot, and ORDER as a non-reserved word doesn't break the existing window or WITHIN GROUP fixtures.

Checked and fine: EXISTS_IN() with no arguments matches how expression_language.md:151 refers to it (no signature given), and the #657 review asked for that fixture. The README's REQUIRED claim for || checks out (expression_language.md:459).

Follow-up (not this PR): could we add || to the Operator Precedence list in core-spec/expression_language.md, between Addition/Subtraction and Comparison? Then the grammar comment can drop the "spec does not say" caveat.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

schema.dataset."Field"
date
first
SUM(order.sales) / COUNT(DISTINCT order.customer_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: this only covers order at the top level. Could we also add SUM(x) OVER (ORDER BY order), so we know the identifier still works right after the ORDER BY keyword?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

assert kind(add.valueExpr(1)) == "MultiplicativeValue"


def test_addition_binds_tighter_than_concat(ossie):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: could we add the mirror case a + b || c here too, asserting ConcatValue with an AdditiveValue on the left? Then both sides of the new level are pinned.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

Comment thread Makefile

.PHONY: test-grammar
test-grammar: DEPENDENCIES := $(UV) java
test-grammar: check-dependencies ## Run ANTLR4 expression grammar tests

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: make test doesn't run this target, which makes sense since java is optional. Could the help text say "(needs java; not part of make test)" so people don't assume it's covered?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

@kayemkim kayemkim 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.

With order, the grammar lets 14 words that SQL:2023 reserves be an unquoted name (group, date, time, row, filter, ...), out of 39 reserved among its 50 keywords (per the SQL Key Words appendix of the PostgreSQL docs), and it refuses the other 25 plus ilike and try_cast. expression_language.md says identifiers "MUST be valid names and follow ANSI SQL naming", and validate.py is looser again: it refuses 12 of the 50 and takes case, end, from and null as dataset names.

The rule in the comment above nonReservedWord, reserved only where a word would make an expression ambiguous, reads like the right one to me. It is in neither the spec nor the README's "Where the grammar goes beyond the spec text" list, so a reader of the spec cannot tell which names need quotes. A line in that README section would cover it here, and I can take the sentence for the Identifiers section to dev@.

@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 LGTM once it's rebased on main, thanks! +1 to @kayemkim's README line on the non-reserved-word rule, here or in a follow-up, since my ORDER ask from #657 lets one more SQL-reserved word go unquoted.

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.

4 participants