Skip to content

Commit

Permalink
Merge pull request #92 from Ariana-B/fix-isnull-json-formatting
Browse files Browse the repository at this point in the history
isNull args as a list
  • Loading branch information
constantinius authored Oct 9, 2024
2 parents e9b6757 + 37d86ac commit 9bde6f1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pygeofilter/backends/cql2_json/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 4 additions & 7 deletions pygeofilter/parsers/cql2_json/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/cql2_json/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/parsers/cql2_json/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 9bde6f1

Please sign in to comment.