From 5b9b3cf9080edbf0d9ac5a83d58e93e0a595e0ac Mon Sep 17 00:00:00 2001 From: Ariana Barzinpour Date: Thu, 28 Mar 2024 02:51:58 +0000 Subject: [PATCH 1/2] isNull args as a list --- pygeofilter/backends/cql2_json/evaluate.py | 2 +- tests/parsers/cql2_json/fixtures.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pygeofilter/backends/cql2_json/evaluate.py b/pygeofilter/backends/cql2_json/evaluate.py index b896bab..52ae315 100644 --- a/pygeofilter/backends/cql2_json/evaluate.py +++ b/pygeofilter/backends/cql2_json/evaluate.py @@ -75,7 +75,7 @@ def like(self, node, *subargs): @handle(ast.IsNull) def isnull(self, node, arg): - return {"op": "isNull", "args": arg} + return {"op": "isNull", "args": [arg]} @handle(ast.Function) def function(self, node, *args): diff --git a/tests/parsers/cql2_json/fixtures.json b/tests/parsers/cql2_json/fixtures.json index 245a59f..4e49be0 100644 --- a/tests/parsers/cql2_json/fixtures.json +++ b/tests/parsers/cql2_json/fixtures.json @@ -33,7 +33,7 @@ }, "Example 9": { "text": "filter=sentinel:data_coverage > 50 OR landsat:coverage_percent < 10 OR (sentinel:data_coverage IS NULL AND landsat:coverage_percent IS NULL)", - "json": "{\"filter-lang\": \"cql2-json\", \"filter\": {\"op\": \"or\", \"args\": [{\"op\": \">\", \"args\": [{\"property\": \"sentinel:data_coverage\"}, 50]}, {\"op\": \"<\", \"args\": [{\"property\": \"landsat:coverage_percent\"}, 10]}, {\"op\": \"and\", \"args\": [{\"op\": \"isNull\", \"args\": {\"property\": \"sentinel:data_coverage\"}}, {\"op\": \"isNull\", \"args\": {\"property\": \"landsat:coverage_percent\"}}]}]}}" + "json": "{\"filter-lang\": \"cql2-json\", \"filter\": {\"op\": \"or\", \"args\": [{\"op\": \">\", \"args\": [{\"property\": \"sentinel:data_coverage\"}, 50]}, {\"op\": \"<\", \"args\": [{\"property\": \"landsat:coverage_percent\"}, 10]}, {\"op\": \"and\", \"args\": [{\"op\": \"isNull\", \"args\": [{\"property\": \"sentinel:data_coverage\"}]}, {\"op\": \"isNull\", \"args\": [{\"property\": \"landsat:coverage_percent\"}]}]}]}}" }, "Example 10": { "text": "filter=eo:cloud_cover BETWEEN 0 AND 50", From 37d86ac19072254eac9ee5c6702a5aedeaebc628 Mon Sep 17 00:00:00 2001 From: Ariana Barzinpour Date: Thu, 28 Mar 2024 03:40:34 +0000 Subject: [PATCH 2/2] fix tests --- pygeofilter/parsers/cql2_json/parser.py | 11 ++++------- tests/parsers/cql2_json/test_parser.py | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pygeofilter/parsers/cql2_json/parser.py b/pygeofilter/parsers/cql2_json/parser.py index 74b41da..e1eb503 100644 --- a/pygeofilter/parsers/cql2_json/parser.py +++ b/pygeofilter/parsers/cql2_json/parser.py @@ -125,7 +125,10 @@ def walk_cql_json(node: JsonType): # noqa: C901 return ast.Not(cast(ast.Node, walk_cql_json(args))) elif op == "isNull": - return ast.IsNull(cast(ast.Node, walk_cql_json(args)), False) + # like with "not", allow both arrays and objects + if isinstance(args, list): + args = args[0] + return ast.IsNull(cast(ast.Node, walk_cql_json(args)), not_=False) elif op == "between": return ast.Between( @@ -153,12 +156,6 @@ def walk_cql_json(node: JsonType): # noqa: C901 not_=False, ) - elif op == "isNull": - return ast.IsNull( - walk_cql_json(args), - not_=False, - ) - elif op in BINARY_OP_PREDICATES_MAP: args = [cast(ast.Node, walk_cql_json(arg)) for arg in args] return BINARY_OP_PREDICATES_MAP[op](*args) diff --git a/tests/parsers/cql2_json/test_parser.py b/tests/parsers/cql2_json/test_parser.py index b78d440..c28ef6e 100644 --- a/tests/parsers/cql2_json/test_parser.py +++ b/tests/parsers/cql2_json/test_parser.py @@ -145,7 +145,7 @@ def test_attribute_in_list(): def test_attribute_is_null(): - result = parse({"op": "isNull", "args": {"property": "attr"}}) + result = parse({"op": "isNull", "args": [{"property": "attr"}]}) assert result == ast.IsNull(ast.Attribute("attr"), False)