geopython / geopython/pygeofilter

A_CONTAINS with cql2_text throws error

Open
#160 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
90
Forks
44
PR merge metrics
No merged PRs in 30d

Description

**Description**

I noticed `A_CONTAINS` doesn't work with cql2_text, though cql2_json can parse it.

**Steps to Reproduce**
Steps to reproduce the behavior:

```
> from pygeofilter.parsers.cql2_text.parser import parse
> parse("A_CONTAINS('values', ('a', 'b', 'c'))")
Traceback (most recent call last):
File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser_state.py", line 77, in feed_token
action, arg = states[state][token.type]
~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'COMMA'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "~/pygeofilter/pygeofilter/parsers/cql2_text/parser.py", line 212, in parse
return parser.parse(cql_text)
^^^^^^^^^^^^^^^^^^^^^^
File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/lark.py", line 677, in parse
return self.parser.parse(text, start=start, on_error=on_error)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parser_frontends.py", line 131, in parse
return self.parser.parse(stream, chosen_start, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 42, in parse
return self.parser.parse(lexer, start)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 88, in parse
return self.parse_from_state(parser_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 111, in parse_from_state
raise e
File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 102, in parse_from_state
state.feed_token(token)
File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser_state.py", line 80, in feed_token
raise UnexpectedToken(token, expected, state=self, interactive_parser=None)
lark.exceptions.UnexpectedToken: Unexpected token Token('COMMA', ',') at line 1, column 26.
Expected one of:
* RPAR
```

**Expected behavior**

It should output this (per output of cql2_json for the same statement as json):

```
> from pygeofilter.parsers.cql2_text.parser import parse
> parse({"op": "a_contains", "args": [{"property": "values"}, ['a', 'b', 'c']]})
ArrayContains(lhs=ATTRIBUTE values, rhs=['a', 'b', 'c'])
```

**Screenshots/Tracebacks**
If applicable, add screenshots to help explain your problem.

**Environment**
- OS: OSX (Tahoe 26)
- Python version: 3.12
- pygeoapi version: 0.4.0 on master (commit 6c8ebac75100cddf7df7a38c305964116ffac527)

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start at pygeofilter/parsers/cql2_text/parser.py and reproduce the failing A_CONTAINS expression shown in the issue. Compare its handling with the equivalent cql2_json input, then verify that cql2_text returns ArrayContains with the attribute and list values instead of raising UnexpectedToken.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.