cedarkit-query 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cedarkit_query-0.2.2/src/cedarkit_query.egg-info → cedarkit_query-0.2.3}/PKG-INFO +1 -1
- cedarkit_query-0.2.3/docs/using-v1.md +11 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/pyproject.toml +1 -1
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/__init__.py +2 -1
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/resources.py +81 -15
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3/src/cedarkit_query.egg-info}/PKG-INFO +1 -1
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/test_resources.py +86 -0
- cedarkit_query-0.2.2/docs/using-v1.md +0 -5
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/LICENSE +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/MANIFEST.in +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/README.md +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/docs/normalization-v1.md +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/docs/protocol-v1.md +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/examples/catalog.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/examples/request.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/scripts/build_schemas.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/scripts/check_dist.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/setup.cfg +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/_json.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/errors.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/model.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/normalize.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/parameters.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/catalog-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/common-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/context-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/error-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/explanation-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/mappings-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/parameters-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/query-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/report-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/request-v1.schema.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/validation.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query.egg-info/SOURCES.txt +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query.egg-info/dependency_links.txt +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query.egg-info/requires.txt +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query.egg-info/top_level.txt +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/conftest.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/test_normalize.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/test_parameters.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/test_protocol.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/test_scopes.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/test_vectors.py +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/vectors/v1/invalid.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/vectors/v1/normalization.json +0 -0
- {cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/tests/vectors/v1/valid.json +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Use a native request
|
|
2
|
+
|
|
3
|
+
Load the request with `Request.load(path)` or build it from a mapping. Use `Query` to set native predicates and optional coordinate constraints. Use `reki.from_source(request.source, context=request.context)` and `source.sel(request.queries)` to execute the selection.
|
|
4
|
+
|
|
5
|
+
See [the native protocol](protocol-v1.md) and [the example request](../examples/request.json).
|
|
6
|
+
|
|
7
|
+
## Validate GRIB2 definitions for a file source
|
|
8
|
+
|
|
9
|
+
`validate_standalone_grib2(parameters, mappings)` accepts a parameter registry and a single GRIB2 mapping resource as dictionaries or validated models. It returns effective definitions by stable ID for `prepare_queries`. Each name and alias must resolve within the registry. Mapping and table `applies_to` scopes must be empty. Use `when` for query conditions and `native.match` for GRIB2 header predicates. Two rules may coexist when their effective query conditions or their native predicates are disjoint.
|
|
10
|
+
|
|
11
|
+
Use `validate_resource_set(parameters, mappings, catalog, dataset_id)` to validate mappings selected by a catalog product.
|
|
@@ -29,7 +29,7 @@ from .normalize import (
|
|
|
29
29
|
query_identity,
|
|
30
30
|
)
|
|
31
31
|
from .parameters import prepare_queries
|
|
32
|
-
from .resources import validate_resource_set
|
|
32
|
+
from .resources import validate_resource_set, validate_standalone_grib2
|
|
33
33
|
|
|
34
34
|
__all__ = [
|
|
35
35
|
"Query",
|
|
@@ -44,6 +44,7 @@ __all__ = [
|
|
|
44
44
|
"Parameters",
|
|
45
45
|
"Mappings",
|
|
46
46
|
"validate_resource_set",
|
|
47
|
+
"validate_standalone_grib2",
|
|
47
48
|
"Context",
|
|
48
49
|
"load_value",
|
|
49
50
|
"load_prevalidated_resource",
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"""Pure validation for definitions, mappings and catalog resource combinations."""
|
|
2
2
|
|
|
3
|
-
from ._json import canonical, plain
|
|
3
|
+
from ._json import canonical, plain, pointer
|
|
4
4
|
from .errors import QueryError
|
|
5
|
-
from .normalize import
|
|
5
|
+
from .normalize import (
|
|
6
|
+
_intersection,
|
|
7
|
+
_normal_selector,
|
|
8
|
+
_normalize,
|
|
9
|
+
constrain_query,
|
|
10
|
+
intersect_scopes,
|
|
11
|
+
)
|
|
6
12
|
|
|
7
13
|
|
|
8
14
|
def _error(path, message):
|
|
@@ -141,6 +147,78 @@ def validate_resource(data, kind):
|
|
|
141
147
|
) from exc
|
|
142
148
|
|
|
143
149
|
|
|
150
|
+
def _mapping_conditions(row, definition, path):
|
|
151
|
+
fixed = {
|
|
152
|
+
key: value
|
|
153
|
+
for key, value in definition["fixed_conditions"].items()
|
|
154
|
+
if key != "statistics"
|
|
155
|
+
}
|
|
156
|
+
try:
|
|
157
|
+
return constrain_query(row["when"], fixed).to_dict()
|
|
158
|
+
except QueryError as exc:
|
|
159
|
+
raise QueryError(
|
|
160
|
+
"invalid_config", path + "/when", "mapping conflicts with parameter conditions"
|
|
161
|
+
) from exc
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _native_overlap(left, right):
|
|
165
|
+
for key in left.keys() & right.keys():
|
|
166
|
+
a, b = left[key], right[key]
|
|
167
|
+
if isinstance(b, dict):
|
|
168
|
+
a, b = b, a
|
|
169
|
+
kind = "number" if isinstance(a, dict) else "literal"
|
|
170
|
+
if kind == "number" and not isinstance(b, dict):
|
|
171
|
+
values = b if isinstance(b, list) else [b]
|
|
172
|
+
b = [value for value in values if type(value) in (int, float)]
|
|
173
|
+
if _intersection(a, b, kind) is None:
|
|
174
|
+
return False
|
|
175
|
+
return True
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def validate_standalone_grib2(parameters, mappings):
|
|
179
|
+
"""Validate an independent GRIB2 mapping resource and return effective definitions."""
|
|
180
|
+
from .model import Mappings
|
|
181
|
+
|
|
182
|
+
effective = effective_parameters(parameters)
|
|
183
|
+
names = {}
|
|
184
|
+
for pid, definition in effective.items():
|
|
185
|
+
for name in (definition["name"], *definition.get("aliases", ())):
|
|
186
|
+
if names.setdefault(name, pid) != pid:
|
|
187
|
+
_error(
|
|
188
|
+
pointer(("parameters", pid, "aliases")),
|
|
189
|
+
f"ambiguous parameter name or alias {name!r}",
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
mappings = mappings if type(mappings) is Mappings else Mappings(mappings)
|
|
193
|
+
resource = mappings.to_dict()
|
|
194
|
+
if resource["backend"] != "grib2":
|
|
195
|
+
_error("/backend", "standalone mappings require the grib2 backend")
|
|
196
|
+
for index, table in enumerate(resource["tables"]):
|
|
197
|
+
if table["applies_to"]:
|
|
198
|
+
_error(
|
|
199
|
+
f"/tables/{index}/applies_to", "standalone tables require an empty scope"
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
applicable = []
|
|
203
|
+
for index, row in enumerate(resource["mappings"]):
|
|
204
|
+
pid = row["parameter_id"]
|
|
205
|
+
path = f"/mappings/{index}"
|
|
206
|
+
if pid not in effective:
|
|
207
|
+
_error(path + "/parameter_id", "unknown mapped parameter ID")
|
|
208
|
+
if row["applies_to"]:
|
|
209
|
+
_error(path + "/applies_to", "standalone mappings require an empty scope")
|
|
210
|
+
bound = _mapping_conditions(row, effective[pid], path)
|
|
211
|
+
native = row["native"]["match"]
|
|
212
|
+
for other_id, other_native, other_bound in applicable:
|
|
213
|
+
if (
|
|
214
|
+
_native_overlap(native, other_native)
|
|
215
|
+
and intersect_scopes(bound, other_bound) is not None
|
|
216
|
+
):
|
|
217
|
+
_error(path + "/native/match", f"overlapping standalone mapping {other_id!r}")
|
|
218
|
+
applicable.append((row["id"], native, bound))
|
|
219
|
+
return effective
|
|
220
|
+
|
|
221
|
+
|
|
144
222
|
def validate_resource_set(parameters, mappings, catalog, dataset_id):
|
|
145
223
|
"""Validate the selected dataset's resource references and return effective definitions."""
|
|
146
224
|
from .model import Catalog, Mappings
|
|
@@ -196,19 +274,7 @@ def validate_resource_set(parameters, mappings, catalog, dataset_id):
|
|
|
196
274
|
path + "/applies_to",
|
|
197
275
|
"mapping refers to an unavailable product or version",
|
|
198
276
|
)
|
|
199
|
-
|
|
200
|
-
k: v
|
|
201
|
-
for k, v in effective[pid]["fixed_conditions"].items()
|
|
202
|
-
if k != "statistics"
|
|
203
|
-
}
|
|
204
|
-
try:
|
|
205
|
-
bound = constrain_query(row["when"], fixed).to_dict()
|
|
206
|
-
except QueryError as exc:
|
|
207
|
-
raise QueryError(
|
|
208
|
-
"invalid_config",
|
|
209
|
-
path + "/when",
|
|
210
|
-
"mapping conflicts with parameter conditions",
|
|
211
|
-
) from exc
|
|
277
|
+
bound = _mapping_conditions(row, effective[pid], path)
|
|
212
278
|
backend = resource["backend"]
|
|
213
279
|
native = canonical(row["native"]["match"])
|
|
214
280
|
time_scope = {"time": applies["time"]} if "time" in applies else {}
|
|
@@ -10,6 +10,7 @@ from cedarkit_query import (
|
|
|
10
10
|
load_value,
|
|
11
11
|
prepare_queries,
|
|
12
12
|
validate_resource_set,
|
|
13
|
+
validate_standalone_grib2,
|
|
13
14
|
)
|
|
14
15
|
from cedarkit_query import model
|
|
15
16
|
from cedarkit_query.resources import effective_parameters
|
|
@@ -141,6 +142,91 @@ def test_resource_set_reuses_validated_models(monkeypatch):
|
|
|
141
142
|
validate_resource_set(parameters, [mappings], catalog, "missing")
|
|
142
143
|
|
|
143
144
|
|
|
145
|
+
@pytest.fixture
|
|
146
|
+
def standalone():
|
|
147
|
+
parameters = snapshot([BASE, {**VARIANT, "aliases": ["2t"]}])
|
|
148
|
+
mappings = {
|
|
149
|
+
"api_version": "cedarkit.mappings/v1",
|
|
150
|
+
"id": "test.generic.grib2",
|
|
151
|
+
"version": "1",
|
|
152
|
+
"backend": "grib2",
|
|
153
|
+
"tables": [],
|
|
154
|
+
"mappings": [
|
|
155
|
+
{
|
|
156
|
+
"id": "t2m",
|
|
157
|
+
"parameter_id": "cedarkit.t2m",
|
|
158
|
+
"backend": "grib2",
|
|
159
|
+
"applies_to": {},
|
|
160
|
+
"when": {},
|
|
161
|
+
"evidence": [],
|
|
162
|
+
"native": {"match": {"tablesVersion": {"range": {"start": 1, "end": 37}}}},
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
}
|
|
166
|
+
return parameters, mappings
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def test_standalone_resolves_public_alias_and_inherits_conditions(standalone):
|
|
170
|
+
parameters, mappings = standalone
|
|
171
|
+
effective = validate_standalone_grib2(Parameters(parameters), Mappings(mappings))
|
|
172
|
+
assert effective["cedarkit.t2m"]["unit"] == "K"
|
|
173
|
+
for token in ("cedarkit.t2m", "t2m", "2t"):
|
|
174
|
+
(selected,) = prepare_queries([{"parameter": token}], effective)
|
|
175
|
+
assert selected.to_dict() == {"parameter": "cedarkit.t2m", **HEIGHT}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def test_standalone_rejects_ambiguous_alias(standalone):
|
|
179
|
+
parameters, mappings = standalone
|
|
180
|
+
parameters["parameters"][0] = {**BASE, "aliases": ["2t"]}
|
|
181
|
+
with pytest.raises(QueryError, match="ambiguous parameter name or alias"):
|
|
182
|
+
validate_standalone_grib2(parameters, mappings)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@pytest.mark.parametrize(
|
|
186
|
+
"changes, path",
|
|
187
|
+
[
|
|
188
|
+
({"parameter_id": "unregistered"}, "/parameter_id"),
|
|
189
|
+
({"applies_to": {"dataset": "example"}}, "/applies_to"),
|
|
190
|
+
({"applies_to": {"product": "orig"}}, "/applies_to"),
|
|
191
|
+
({"applies_to": {"product_version": "current"}}, "/applies_to"),
|
|
192
|
+
({"applies_to": {"time": "2026-11-02T12:00:00Z"}}, "/applies_to"),
|
|
193
|
+
({"when": {"level": 10}}, "/when"),
|
|
194
|
+
],
|
|
195
|
+
)
|
|
196
|
+
def test_standalone_requires_compatible_and_independent_rows(standalone, changes, path):
|
|
197
|
+
parameters, mappings = standalone
|
|
198
|
+
mappings["mappings"][0].update(changes)
|
|
199
|
+
with pytest.raises(QueryError) as caught:
|
|
200
|
+
validate_standalone_grib2(parameters, mappings)
|
|
201
|
+
assert (caught.value.code, caught.value.path) == ("invalid_config", "/mappings/0" + path)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@pytest.mark.parametrize(
|
|
205
|
+
"selector, when, overlaps",
|
|
206
|
+
[
|
|
207
|
+
(4, {}, True),
|
|
208
|
+
({"range": {"start": 32, "end": 40}}, HEIGHT, True),
|
|
209
|
+
({"range": {"start": 38, "end": 40}}, {}, False),
|
|
210
|
+
(["32", 38], {}, False),
|
|
211
|
+
(4, {"level_type": "pressure", "level": 850}, False),
|
|
212
|
+
],
|
|
213
|
+
)
|
|
214
|
+
def test_standalone_checks_native_and_effective_conditions(standalone, selector, when, overlaps):
|
|
215
|
+
parameters, mappings = standalone
|
|
216
|
+
mappings["mappings"].append({
|
|
217
|
+
**mappings["mappings"][0],
|
|
218
|
+
"id": "other",
|
|
219
|
+
"parameter_id": "cedarkit.t",
|
|
220
|
+
"when": when,
|
|
221
|
+
"native": {"match": {"tablesVersion": selector}},
|
|
222
|
+
})
|
|
223
|
+
if overlaps:
|
|
224
|
+
with pytest.raises(QueryError, match="overlapping standalone mapping"):
|
|
225
|
+
validate_standalone_grib2(parameters, mappings)
|
|
226
|
+
else:
|
|
227
|
+
validate_standalone_grib2(parameters, mappings)
|
|
228
|
+
|
|
229
|
+
|
|
144
230
|
@pytest.mark.parametrize(
|
|
145
231
|
"rows,path",
|
|
146
232
|
[
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# Use a native request
|
|
2
|
-
|
|
3
|
-
Load the request with `Request.load(path)` or build it from a mapping. Use `Query` to set native predicates and optional coordinate constraints. Use `reki.from_source(request.source, context=request.context)` and `source.sel(request.queries)` to execute the selection.
|
|
4
|
-
|
|
5
|
-
See [the native protocol](protocol-v1.md) and [the example request](../examples/request.json).
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/catalog-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/common-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/context-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/error-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/explanation-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/mappings-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/parameters-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/query-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/report-v1.schema.json
RENAMED
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query/schemas/request-v1.schema.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cedarkit_query-0.2.2 → cedarkit_query-0.2.3}/src/cedarkit_query.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|