Skip to content

Commit a10c5a2

Browse files
Updating mapping to double for long
1 parent e45cfea commit a10c5a2

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
},
104104
# Default all other strings not otherwise specified to keyword
105105
{"strings": {"match_mapping_type": "string", "mapping": {"type": "keyword"}}},
106-
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "float"}}},
106+
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "double"}}},
107107
]
108108

109109
ES_ITEMS_MAPPINGS = {

stac_fastapi/tests/api/test_api.py

+73
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import random
12
import uuid
3+
from copy import deepcopy
24
from datetime import datetime, timedelta, timezone
35

46
import pytest
@@ -459,3 +461,74 @@ async def test_search_line_string_intersects(app_client, ctx):
459461

460462
resp_json = resp.json()
461463
assert len(resp_json["features"]) == 1
464+
465+
466+
@pytest.mark.asyncio
467+
@pytest.mark.parametrize(
468+
"value, expected",
469+
[
470+
(32767, 1), # Short Limit,
471+
(2147483647, 1), # Int Limit
472+
(2147483647 + 5000, 1), # Above int Limit
473+
# All below fail, return three values
474+
(21474836470, 1), # Above int Limit
475+
# This value still fails to return 1
476+
# Commenting out
477+
(9223372036854775807, 2),
478+
],
479+
)
480+
async def test_big_int_eo_search(
481+
app_client, txn_client, test_item, test_collection, value, expected
482+
):
483+
484+
random_str = "".join(random.choice("abcdef") for i in range(random.randint(1, 5)))
485+
collection_id = f"test-collection-eo-{random_str}"
486+
487+
test_big_int_item = test_item
488+
del test_big_int_item["properties"]["eo:bands"]
489+
test_big_int_item["collection"] = collection_id
490+
test_big_int_collection = test_collection
491+
test_big_int_collection["id"] = collection_id
492+
493+
# type number
494+
attr = "eo:full_width_half_max"
495+
496+
stac_extensions = [
497+
"https://stac-extensions.github.io/eo/v2.0.0/schema.json",
498+
]
499+
500+
test_collection["stac_extensions"] = stac_extensions
501+
502+
test_item["stac_extensions"] = stac_extensions
503+
504+
await create_collection(txn_client, test_collection)
505+
506+
for val in [
507+
value,
508+
value + random.randint(10, 1010),
509+
value - random.randint(10, 1010),
510+
]:
511+
item = deepcopy(test_item)
512+
item["id"] = str(uuid.uuid4())
513+
item["properties"][attr] = val
514+
await create_item(txn_client, item)
515+
516+
params = {
517+
"collections": [item["collection"]],
518+
"filter": {
519+
"args": [
520+
{
521+
"args": [
522+
{"property": f"properties.{attr}"},
523+
value,
524+
],
525+
"op": "=",
526+
}
527+
],
528+
"op": "and",
529+
},
530+
}
531+
resp = await app_client.post("/search", json=params)
532+
resp_json = resp.json()
533+
results = set([x["properties"][attr] for x in resp_json["features"]])
534+
assert len(results) == expected

0 commit comments

Comments
 (0)