Skip to content

Add CQL2 array predicates, cql-json \ e\ support, and parser validation - #161

Open
Nortaq-PlayNexus wants to merge 1 commit into
geopython:mainfrom
Nortaq-PlayNexus:fix/cql2-arrays-and-cql-json-validation
Open

Add CQL2 array predicates, cql-json \ e\ support, and parser validation#161
Nortaq-PlayNexus wants to merge 1 commit into
geopython:mainfrom
Nortaq-PlayNexus:fix/cql2-arrays-and-cql-json-validation

Conversation

@Nortaq-PlayNexus

Copy link
Copy Markdown

Closes #19, #47, #144, #160

Changes

cql2_text: array predicates (#160)
A_EQUALS, A_CONTAINS, A_CONTAINEDBY, and A_OVERLAPS are now supported, with either an array literal (('a', 'b', 'c')) or an attribute on the right-hand side, matching the CQL2 spec. Previously A_CONTAINS('values', ('a', 'b', 'c')) raised a LALR error (KeyError: 'COMMA').

  • parsers/cql2_text/grammar.lark: added array_predicate and array_literal rules
  • parsers/cql2_text/parser.py: added binary_array_predicate and array_literal transformer methods using the existing ARRAY_PREDICATES_MAP

cql2_text: single-character attribute names (#144)
The attribute terminal regex used +, so names like a could not be parsed. Changed to * ([a-zA-Z][a-zA-Z_:0-9.]*) so a = 1 parses correctly.

cql-json: ne comparison operator (#19)
{"ne": [...]} now produces ast.NotEqual, completing the CQL2 comparison operator set for the JSON parser.

cql-json: malformed-expression validation (#47)

  • Nodes with more than one predicate key (e.g. {"and": [...], "or": [...]}) now raise ValueError("multiple predicates ...") instead of silently picking one.
  • and/or with fewer than 2 operands now raise ValueError("at least 2 operands") instead of producing a wrong AST.

Testing

  • 11 new tests across tests/parsers/cql2_text/test_parser.py and tests/parsers/cql_json/test_parser.py
  • 294 passed locally (tests/parsers, tests/native, tests/test_utils.py)
  • ruff check clean on all changed Python files

- cql2_text: support array predicates (A_EQUALS, A_CONTAINS, A_CONTAINEDBY,
  A_OVERLAPS) with array literals or attributes (fixes geopython#160)
- cql2_text: allow single-character attribute names (fixes geopython#144)
- cql-json: add ne comparison operator (fixes geopython#19)
- cql-json: validate multiple predicate keys and and/or arity (fixes geopython#47)
- update CHANGELOG and add tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cql-json COMPARISON_MAP does not contain <>

1 participant