Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isNull args as a list #92

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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