-
-
Notifications
You must be signed in to change notification settings - Fork 314
Description
Is your feature request related to a problem? Please describe.
RIght now, pygeoapi uses ecql to parse text CQL filters:
https://github.com/geopython/pygeoapi/blob/master/pygeoapi/api/itemtypes.py#L46
https://github.com/geopython/pygeoapi/blob/master/pygeoapi/api/itemtypes.py#L489-L491
But pygeoapi then uses CQL2 to parse JSON CQL bodies:
https://github.com/geopython/pygeoapi/blob/master/pygeoapi/api/itemtypes.py#L47
https://github.com/geopython/pygeoapi/blob/master/pygeoapi/api/itemtypes.py#L504-L507
ECQL is not equivalent to CQL2. One difference is that ECQL supports using the "ILIKE" operator for case-insensitive "LIKE" operations, which CQL2 does not; CQL2 meanwhile supports using "CASEI" for case folding of attributes and variables, which ECQL does not:
pygeofilter parse cql2_text "CASEI('road_class') LIKE '%Street%'"
# Parsing cql2_text query into AST
# Like(lhs=Function(name='lower', arguments=['road_class']), pattern='%Street%', nocase=False, wildcard='%', singlechar='.', escapechar='\\', not_=False)
pygeofilter parse cql2_text "'road_class' ILIKE '%Street%'"
# Parsing cql2_text query into AST
# Error: Unexpected token Token('__ANON_4', 'ILIKE') at line 1, column 14.
# Expected one of:
# <snip>
# Previous tokens: [Token('SINGLE_QUOTED', "'road_class'")]
pygeofilter parse ecql "'road_class' ILIKE '%Street%'"
# Parsing ecql query into AST
# Like(lhs='road_class', pattern='%Street%', nocase=True, wildcard='%', singlechar='.', escapechar='\\', not_=False)
pygeofilter parse cql2_text "'road_class' ILIKE '%Street%'"
# Parsing cql2_text query into AST
# Error: Unexpected token Token('__ANON_4', 'ILIKE') at line 1, column 14.
# Expected one of:
# <snip>
# Previous tokens: [Token('SINGLE_QUOTED', "'road_class'")]As a result, different operations are supported when using text versus JSON CQL filters.
OGC API Features Part 3 Recommendation 4 says:
If a filter expression can be represented for its intended use as text, servers SHOULD support the CQL2 text encoding.
Describe the solution you'd like
For consistency across the text and JSON CQL filters, I wonder if it makes sense to use the cql2_text parser for text filters.
Describe alternatives you've considered
It could also make sense to enable both ECQL and CQL2-Text and allow users to specify which parser to use via the filter-lang query parameter. To avoid a breaking change, filter could default to assuming ECQL unless specified otherwise. Part 3 does allow for non-CQL2 filter languages to be used, though states only CQL2 is recommended by the standard.
Additional context
I believe this is the root cause of #2015; pygeoapi is using the ECQL parser, and ECQL is case-sensitive.