Skip to content

Commit

Permalink
fix pygeofilter issue and bump min version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariana Barzinpour authored and Ariana-B committed Jul 24, 2024
1 parent 23b4c93 commit b7b8d53
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
22 changes: 4 additions & 18 deletions cubedash/summary/_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
from geoalchemy2 import WKBElement
from geoalchemy2 import shape as geo_shape
from geoalchemy2.shape import from_shape, to_shape
from pygeofilter import ast
from pygeofilter.backends.evaluator import handle
from pygeofilter.backends.sqlalchemy.evaluate import SQLAlchemyFilterEvaluator
from pygeofilter.backends.sqlalchemy.evaluate import (
SQLAlchemyFilterEvaluator as FilterEvaluator,
)
from pygeofilter.parsers.cql2_json import parse as parse_cql2_json
from pygeofilter.parsers.cql2_text import parse as parse_cql2_text
from shapely.geometry.base import BaseGeometry
Expand All @@ -43,7 +43,6 @@
exists,
func,
literal,
null,
or_,
select,
union_all,
Expand Down Expand Up @@ -1267,7 +1266,7 @@ def _add_filter_to_query(
if filter_lang == "cql2-text"
else parse_cql2_json(filter_cql)
)
query = query.filter(FilterEvaluator(field_exprs).evaluate(filter_cql))
query = query.filter(FilterEvaluator(field_exprs, True).evaluate(filter_cql))

return query

Expand Down Expand Up @@ -1881,19 +1880,6 @@ def get_dataset_footprint_region(self, dataset_id):
)


class FilterEvaluator(SQLAlchemyFilterEvaluator):
"""
Since pygeofilter's SQLAlchemyFilterEvaluator doesn't support treating
invalid/undefined attributes as NULL as per the STAC API Filter spec,
this class overwrites the Evaluator's handling of attributes to return NULL
as the default value if a field is not present in the mapping of sqlalchemy expressions.
"""

@handle(ast.Attribute)
def attribute(self, node: ast.Attribute):
return self.field_mapping.get(node.name, null())


def _refresh_data(please_refresh: Set[PleaseRefresh], store: SummaryStore):
"""
Refresh product information after a schema update, plus the given kind of data.
Expand Down
12 changes: 6 additions & 6 deletions docs/rtd-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ datacube==1.8.18
dateparser==1.2.0
# via pygeofilter
defusedxml==0.7.1
# via datacube
deprecat==2.1.1
# via eodatasets3
deprecat==2.1.1
# via datacube
distributed==2023.1.1
# via datacube
eodatasets3==0.30.1
Expand Down Expand Up @@ -196,9 +196,9 @@ psutil==5.9.4
# via distributed
psycopg2==2.9.5
# via datacube
pygeofilter==0.2.1
pygeofilter==0.2.4
# via datacube-explorer (setup.py)
pygeoif==1.4.0
pygeoif==1.5.0
# via pygeofilter
pyorbital==1.7.3
# via datacube-explorer (setup.py)
Expand Down Expand Up @@ -241,7 +241,7 @@ referencing==0.32.0
# via
# jsonschema
# jsonschema-specifications
regex==2023.12.25
regex==2024.5.15
# via dateparser
requests==2.28.2
# via pyorbital
Expand Down Expand Up @@ -296,7 +296,7 @@ toolz==0.12.0
# partd
tornado==6.2
# via distributed
typing-extensions==4.11.0
typing-extensions==4.12.2
# via pygeoif
tzlocal==5.2
# via dateparser
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"sqlalchemy>=1.4",
"structlog>=20.2.0",
"pytz",
"pygeofilter",
"pygeofilter>=0.2.2",
],
tests_require=tests_require,
extras_require=extras_require,
Expand Down

0 comments on commit b7b8d53

Please sign in to comment.