Skip to content

fix(cql2-json): accept a property reference as an interval bound - #178

Open
C1-BA-B1-F3 wants to merge 1 commit into
geopython:mainfrom
C1-BA-B1-F3:fix/cql2-json-interval-property-bounds
Open

C1-BA-B1-F3 wants to merge 1 commit into
geopython:mainfrom
C1-BA-B1-F3:fix/cql2-json-interval-property-bounds

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Fixes #116.

An interval bound was assumed to be a date/time string, so

{"interval": [{"property": "start"}, {"property": "end"}]}

died in walk_cql_json with AttributeError: 'dict' object has no attribute 'split'. That shape is CQL2 conformance test 41 and is how T_CONTAINS(interval(a, b), interval(t1, t2)) is written (the linked pycql2 schema in the issue thread allows it too).

The fix walks a non-string bound like any other expression, so it becomes an ast.Node that the evaluator resolves as usual, and widens values.Interval.start/end to admit an expression — the class already carried one through get_sub_nodes, its annotation was just narrower than its own API.

Scope — what this does and does not cover

Verified:

  • parses, for a property bound, an open bound (".."), and a function bound;
  • round-trips through the cql2-json backend:
    to_cql2(parse(q)) → {"op": "t_contains", "args": [{"interval": [{"property": "start_datetime"}, {"property": "end_datetime"}]}, ...]}.

Not covered, and reproducible on this branch: evaluating an interval on the left-hand side. The SQLAlchemy backend's filters.temporal() splits its second argument into low, high and compares a single column against them, so a two-column interval on the left raises

TypeError: '>=' not supported between instances of 'tuple' and 'datetime.datetime'

Fixing that means teaching the backends the interval-vs-interval relations, which is a separate change; I have kept this one to the parsing defect the issue reports. Happy to take that on as a follow-up if you want it.

Tests

4 cases added to tests/parsers/cql2_json/test_parser.py: property/property, property/open, open/property, and a function bound. All 4 fail on the pre-fix code; the module is 45/45 after.

Full suite with the test extra (excluding the modules that need a live Elasticsearch/OpenSearch/Solr or GDAL): 320 passed / 62 skipped / 37 errors against a 316 / 62 / 37 baseline on main — the delta is exactly the 4 new tests; the 37 errors are the network-backed backend suites. ruff / ruff format clean; mypy unchanged from main (same pre-existing values.py shape errors).

An interval bound was assumed to be a date/time string, so

    {"interval": [{"property": "start"}, {"property": "end"}]}

died in ``walk_cql_json`` with
``AttributeError: 'dict' object has no attribute 'split'``. That shape is
CQL2 conformance test 41 and is what
``T_CONTAINS(interval(a, b), interval(t1, t2))`` is written as.

Walk a non-string bound like any other expression, so it becomes an
``ast.Node`` that the evaluator resolves as usual, and widen
``values.Interval.start``/``end`` to admit an expression — the class already
carried one through ``get_sub_nodes``.

This is a parser fix: it makes the filter parse (and round-trip through the
cql2-json backend). Evaluating an interval on the left-hand side is a
separate backend gap, see the PR description.

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

Parsing issues with some temporal functions

1 participant