Add cql-json support for ES (#723)

Fix starlette event loop


Fix starlette event loop


Fix starlette event loop


Fix starlette event loop


Fix provider regression


Make method public


Make method public


Move function to the helpers utility


Add the CQL lifecycle for development


Add CQL docs


Fix flake8


Isolate import for starlette codepath
This commit is contained in:
Francesco Bartoli
2021-07-22 03:00:14 +02:00
committed by GitHub
parent 0f38c764d6
commit bb4cd0bf69
18 changed files with 1431 additions and 35 deletions
File diff suppressed because one or more lines are too long
+170
View File
@@ -3,6 +3,7 @@
# Authors: Tom Kralidis <tomkralidis@gmail.com>
#
# Copyright (c) 2020 Tom Kralidis
# Copyright (c) 2021 Francesco Bartoli
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
@@ -31,6 +32,7 @@ import pytest
from pygeoapi.provider.base import ProviderItemNotFoundError
from pygeoapi.provider.elasticsearch_ import ElasticsearchProvider
from pygeoapi.models.cql import CQLModel
@pytest.fixture()
@@ -43,6 +45,105 @@ def config():
}
@pytest.fixture()
def config_cql():
return {
'name': 'Elasticsearch',
'type': 'feature',
'data': 'http://localhost:9200/nhsl_hazard_threat_all_indicators_s_bc', # noqa
'id_field': 'Sauid'
}
@pytest.fixture()
def between():
between_ = {
"between": {
"value": {"property": "properties.pop_max"},
"lower": 10000,
"upper": 100000
}
}
return CQLModel.parse_obj(between_)
@pytest.fixture()
def between_upper():
between_ = {
"between": {
"value": {"property": "properties.pop_max"},
"upper": 100000
}
}
return CQLModel.parse_obj(between_)
@pytest.fixture()
def between_lower():
between_ = {
"between": {
"value": {"property": "properties.pop_max"},
"lower": 10000
}
}
return CQLModel.parse_obj(between_)
@pytest.fixture()
def eq():
eq_ = {
"eq": [
{"property": "properties.featurecla"},
"Admin-0 capital"
]
}
return CQLModel.parse_obj(eq_)
@pytest.fixture()
def _and(eq, between):
and_ = {
"and": [
{
"between": {
"value": {
"property": "properties.pop_max"
},
"lower": 100000,
"upper": 1000000
}
},
{
"eq": [
{"property": "properties.featurecla"},
"Admin-0 capital"
]
}
]
}
return CQLModel.parse_obj(and_)
@pytest.fixture()
def intersects():
intersects = {"intersects": [
{"property": "geometry"},
{
"type": "Polygon",
"coordinates": [
[
[10.497565, 41.520355],
[10.497565, 43.308645],
[15.111823, 43.308645],
[15.111823, 41.520355],
[10.497565, 41.520355]
]
]
}
]}
return CQLModel.parse_obj(intersects)
def test_query(config):
p = ElasticsearchProvider(config)
@@ -121,3 +222,72 @@ def test_get_not_existing_item_raise_exception(config):
p = ElasticsearchProvider(config)
with pytest.raises(ProviderItemNotFoundError):
p.get('404')
def test_post_cql_json_between_query(config, between):
"""Testing cql json query for a between object"""
p = ElasticsearchProvider(config)
results = p.query(limit=100, filterq=between)
assert len(results['features']) == 23
assert results['numberMatched'] == 23
assert results['numberReturned'] == 23
for item in results['features']:
assert 10000 <= item["properties"]["pop_max"] <= 100000
def test_post_cql_json_between_lte_query(config, between_upper):
"""Testing cql json query for a between object"""
p = ElasticsearchProvider(config)
results = p.query(limit=100, filterq=between_upper)
assert len(results['features']) == 28
assert results['numberMatched'] == 28
assert results['numberReturned'] == 28
for item in results['features']:
assert item["properties"]["pop_max"] <= 100000
def test_post_cql_json_between_gte_query(config, between_lower):
"""Testing cql json query for a between object"""
p = ElasticsearchProvider(config)
results = p.query(limit=500, filterq=between_lower)
assert len(results['features']) == 237
assert results['numberMatched'] == 237
assert results['numberReturned'] == 237
for item in results['features']:
assert 10000 <= item["properties"]["pop_max"]
def test_post_cql_json_eq_query(config, eq):
"""Testing cql json query for an eq object"""
p = ElasticsearchProvider(config)
results = p.query(limit=500, filterq=eq)
assert len(results['features']) == 235
def test_post_cql_json_and_query(config, _and):
"""Testing cql json query for an and object"""
p = ElasticsearchProvider(config)
results = p.query(limit=1000, filterq=_and)
assert len(results['features']) == 77
def test_post_cql_json_intersects_query(config, intersects):
"""Testing cql json query for an intersects object"""
p = ElasticsearchProvider(config)
results = p.query(limit=100, filterq=intersects)
assert len(results['features']) == 2