Skip to content

docs(core-spec): rank NOT below comparison, where SQL puts it - #614

Open
ayushtkn wants to merge 1 commit into
apache:mainfrom
ayushtkn:fix/not-precedence
Open

ayushtkn wants to merge 1 commit into
apache:mainfrom
ayushtkn:fix/not-precedence

Conversation

@ayushtkn

Copy link
Copy Markdown
Member

Summary

The precedence list grouped NOT with the unary + and - at rank 2, above comparison
at rank 5, which describes NOT a = b as (NOT a) = b.

sqlglot — the parser validation/validate.py already runs over every expression in a
document — reads it the other way:

NOT a = b -> Not(EQ(a, b)) NOT binds looser than comparison

  • a = b -> EQ(Neg(a), b) the real unary - binds tighter, as rank 2 claims
    NOT a AND b -> And(Not(a), b) NOT binds tighter than AND

The contrast with - is the point: a genuine unary operator does bind tighter than
comparison, and NOT does not. It sits between comparison and AND, so it gets its own
rank:

-2. Unary operators: `+`, `-`, `NOT`
+2. Unary operators: `+`, `-`
 5. Comparison: `=`, `<>`, `<`, `>`, `<=`, `>=`, `LIKE`, `IN`, `BETWEEN`, `IS NULL`
-6. Logical AND: `AND`
-7. Logical OR: `OR`
+6. Logical NOT: `NOT`
+7. Logical AND: `AND`
+8. Logical OR: `OR`

NOT a IS NULL, NOT a LIKE 'x', NOT a IN (1) and NOT a BETWEEN 1 AND 2 each parse
as a negation of the whole comparison, which is consistent with rank 6.

NOT is ranked only here. relational_semantics.md, added by #354, has no precedence
section, and the other two mentions in this file give NOT's syntax rather than its
binding.

Related Issues

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

Ontology

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

Converters

  • Converter logic in converters/ is updated to reflect spec or ontology changes
  • New converters include tests under the converter's test directory
  • If adding a new converter, .github/labeler.yml is updated with the new path

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 or converter support

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

The precedence list grouped `NOT` with the unary `+` and `-` at rank 2, above
comparison at rank 5, which describes `NOT a = b` as `(NOT a) = b`.

sqlglot, the parser `validation/validate.py` uses to check every expression in a
document, reads it the other way:

    NOT a = b      ->  Not(EQ(a, b))
    - a = b        ->  EQ(Neg(a), b)
    NOT a AND b    ->  And(Not(a), b)

The contrast with `-` is the point: a genuine unary operator does bind tighter
than comparison, and `NOT` does not. It binds looser than comparison and tighter
than `AND`, so it belongs on its own rank between them. The same holds for the
comparison forms `NOT a IS NULL`, `NOT a LIKE`, `NOT a IN` and `NOT a BETWEEN`,
each of which negates the whole comparison.

`NOT` is listed only here; the other two mentions in this file give its syntax
rather than its binding.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 16:42

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

1 open issue
What changed in this PR

Updates the expression language spec to document NOT operator precedence consistent with how the parser interprets SQL predicates, placing NOT below comparison operators and above AND/OR.

Changes:

  • Remove NOT from the “Unary operators” precedence rank.
  • Introduce a dedicated precedence rank for logical NOT between comparison and AND.
File Description
core-spec/​expression_language.md Adjusts the documented operator precedence list so NOT binds looser than comparisons and tighter than AND/OR.

Review effort: Lite

6. Logical NOT: `NOT`
7. Logical AND: `AND`
8. Logical OR: `OR`

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants