cdm_data_loaders.pipelines.jsonlines.extract_pydantic_validate_pipeline ¶
JSONL validate-and-load pipeline for the KBase CTS.
Reads JSONL files. Validates each record against a Pydantic model. Writes valid and invalid records to separate tables.
The entity models come from an external module set by
entity_models. That module must define:
ENTITY_MODELS: dict[str, type[BaseModel]]
Each key is a table name. Each value is the Pydantic model for that table. Example:
from datetime import date
from pydantic import BaseModel
class Sample(BaseModel):
id: str
collection_date: date
ENTITY_MODELS: dict[str, type[BaseModel]] = {"sample": Sample}
input_dir must contain one subdirectory per table name in
ENTITY_MODELS. Each subdirectory holds that table's JSONL files.
Files may be plain text or gzip-compressed (.jsonl or .jsonl.gz).
Valid records go to a table named after the entity. Records that fail
JSON parsing or model validation go to the _rejected table. Each
rejected record includes the target table name, source file, line number,
raw text, and error detail.
Write disposition is append or replace only. No merge is performed.
build_entity_resource ¶
build_entity_resource(
table_name: str,
model: type[BaseModel],
settings: JsonlPydanticIngestSettings,
) -> DltResource
Build the resource that reads, validates, and routes one entity's records.
Reads files matching settings.file_glob from
settings.input_dir/table_name. If that directory does not exist,
uses an empty file list instead. A missing entity then produces zero
rows, not an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
entity name; also the input_dir subdirectory name |
required |
model
|
type[BaseModel]
|
Pydantic model used to validate this entity's records |
required |
settings
|
JsonlPydanticIngestSettings
|
pipeline settings |
required |
Returns:
| Type | Description |
|---|---|
DltResource
|
resource yielding validated and rejected records for this entity |
Source code in src/cdm_data_loaders/pipelines/jsonlines/extract_pydantic_validate_pipeline.py
run_jsonlines_with_validation_pipeline ¶
Run the JSONL validate-and-load pipeline for every requested table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
JsonlPydanticIngestSettings
|
pipeline configuration |
required |
Returns:
| Type | Description |
|---|---|
LoadInfo | None
|
load information for the pipeline |