Skip to content

fix(cql2_json): accept BETWEEN with flat args per final spec - #175

Open
C1-BA-B1-F3 wants to merge 3 commits into
geopython:mainfrom
C1-BA-B1-F3:fix/cql2-json-between-flat-args
Open

C1-BA-B1-F3 wants to merge 3 commits into
geopython:mainfrom
C1-BA-B1-F3:fix/cql2-json-between-flat-args

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Summary

OGC 21-065r2 (the final CQL2 standard) defines BETWEEN with a flat 3-element args array:

{"op": "between", "args": [{"property": "height"}, 2, 5]}

parsers/cql2_json/parser.py only accepted the draft nested shape args[1][0] / args[1][1]:

return ast.Between(
    cast(ast.Node, walk_cql_json(args[0])),
    cast(ast.ScalarAstType, walk_cql_json(args[1][0])),
    cast(ast.ScalarAstType, walk_cql_json(args[1][1])),
    not_=False,
)

A spec-conformant client's BETWEEN therefore raised TypeError: 'int' object is not subscriptable.

Fix

Accept both shapes: nested when args[1] is a list, flat when it is not.

Test plan

  • New regression tests test_between_flat_args_final_spec and test_between_nested_args_draft_compat cover both shapes.
  • pytest tests/parsers/cql2_json/ — 45/45 pass (43 pre-existing + 2 new).

Fixes #162

The unquoted attribute regex /[a-zA-Z][a-zA-Z_:0-9.]+/ required at
least two characters, so expressions like 'a = 1' or 'S_INTERSECTS(g,
BBOX(...))' failed to parse.

Change the trailing .+ to .* so a single-letter identifier is accepted.

Fixes geopython#165
A GeoJSON bbox literal is [minx, miny, maxx, maxy], but
parsers/cql2_json/parser.py unpacked it directly into
values.Envelope(*bbox) whose field order is (x1, x2, y1, y2) ==
(minx, maxx, miny, maxy). The two conventions were conflated, so
longitudes and latitudes were silently swapped.

Reindex explicitly: Envelope(b[0], b[2], b[1], b[3]).

Fixes geopython#163
OGC 21-065r2 defines BETWEEN with a flat 3-element args array
[operand, low, high]. The parser only accepted the draft nested shape
[operand, [low, high]], so a spec-conformant client raised TypeError.

Accept both: nested when args[1] is a list, flat when it is not.

Fixes geopython#162
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.

cql2-json: BETWEEN expects the draft nested args shape; final-spec flat args raise TypeError

1 participant