Skip to content

Commit bf1c6c4

Browse files
committed
feat: following review, tweak location of additional reader checks config and add json schema support
1 parent b9c872e commit bf1c6c4

6 files changed

Lines changed: 47 additions & 15 deletions

File tree

‎docs/advanced_guidance/json_schemas/contract/components/base_entity.schema.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@
2626
"items": {
2727
"type": "string"
2828
}
29+
},
30+
"reader_additional_checks": {
31+
"description": "A mapping of additional checks to perform on entities after initial read",
32+
"type": "object",
33+
"additionalProperties": {
34+
"$ref": "reader_additional_checks.json"
2935
}
30-
},
36+
}
37+
},
3138

3239
"required": ["fields"]
3340
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "data-ingest:contract/components/reader_additional_checks.schema.json",
4+
"title": "reader_additional_checks",
5+
"description": "Additional checks to perform on initially read entities",
6+
"type": "object",
7+
"properties": {
8+
"error_code": {
9+
"description": "The code to be used for the additional check specified",
10+
"type": "string"
11+
},
12+
"error_message": {
13+
"description": "The message to be displayed for the additional check specified.",
14+
"type": "string"
15+
}
16+
},
17+
"required": [
18+
"error_code",
19+
"error_message"
20+
],
21+
"additionalProperties": false
22+
}

‎src/dve/core_engine/backends/base/reader.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
from dve.core_engine.backends.exceptions import MessageBearingError, ReaderLacksEntityTypeSupport
1212
from dve.core_engine.backends.types import EntityName, EntityType
13-
from dve.core_engine.configuration.v1 import AllowedAdditionalChecks, _ReaderAdditionalChecksConfig
13+
from dve.core_engine.configuration.v1 import (
14+
AllowedAdditionalReaderChecks,
15+
_ReaderAdditionalChecksConfig,
16+
)
1417
from dve.core_engine.message import FeedbackMessage
1518
from dve.core_engine.type_hints import URI, ArbitraryFunction, WrapDecorator
1619
from dve.parser.file_handling.service import open_stream
@@ -111,7 +114,7 @@ def read_to_entity_type(
111114
schema: type[BaseModel],
112115
all_model_fields: Optional[set[str]] = None,
113116
additional_checks: Optional[
114-
dict[AllowedAdditionalChecks, _ReaderAdditionalChecksConfig]
117+
dict[AllowedAdditionalReaderChecks, _ReaderAdditionalChecksConfig]
115118
] = None,
116119
):
117120
"""Read to the specified entity type, if supported.

‎src/dve/core_engine/configuration/v1/__init__.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"""The operation """
5858
RuleType = type[AbstractStep]
5959
"""The metadata step type implemented by the rule."""
60-
AllowedAdditionalChecks = Literal["check_empty"]
60+
AllowedAdditionalReaderChecks = Literal["check_empty"]
6161
"""Additional checks to be performed in the file_transformation stage"""
6262

6363

@@ -162,10 +162,6 @@ class _ReaderConfig(BaseModel): # type: ignore
162162
"""Keyword arguments for the reader."""
163163
field_names: Optional[list[str]] = None
164164
"""The field names to request from the reader. These are deprecated and will not be used."""
165-
additional_checks: dict[AllowedAdditionalChecks, _ReaderAdditionalChecksConfig] = Field(
166-
default_factory=dict
167-
)
168-
"""Additional checks to be performed after the entity is read"""
169165

170166

171167
class _ModelConfig(_SchemaConfig):
@@ -177,6 +173,10 @@ class _ModelConfig(_SchemaConfig):
177173
"""A single key field to be used by the model."""
178174
reader_config: dict[Extension, _ReaderConfig]
179175
"""Reader configuration options for the model."""
176+
reader_additional_checks: dict[AllowedAdditionalReaderChecks, _ReaderAdditionalChecksConfig] = (
177+
Field(default_factory=dict)
178+
)
179+
"""Additional checks to be performed after the entity is read"""
180180
aliases: dict[FieldName, FieldName] = Field(default_factory=dict)
181181
"""An alias field name mapping."""
182182

‎src/dve/pipeline/pipeline.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def write_file_to_parquet(
238238
model_name,
239239
stringify_model(model), # type: ignore
240240
get_all_model_fields(models.values()), # type: ignore
241-
dataset[model_name].reader_config[f".{ext.lower()}"].additional_checks,
241+
dataset[model_name].reader_additional_checks,
242242
),
243243
f"{out}{model_name}",
244244
)

‎tests/testdata/flights/flights_add_reader_checks.dischema.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
"kwargs": {
4545
"record_tag": "airport",
4646
"root_tag": "country"
47-
},
48-
"additional_checks": {
49-
"check_empty": {
50-
"error_code": "AIRPORTEMPTY",
51-
"error_message": "No airport records included in submission"
52-
}
5347
}
5448
}
5549
},
50+
"reader_additional_checks": {
51+
"check_empty": {
52+
"error_code": "AIRPORTEMPTY",
53+
"error_message": "No airport records included in submission"
54+
}
55+
},
5656
"key_field": "airport_id",
5757
"mandatory_fields": [
5858
"airport_id"

0 commit comments

Comments
 (0)