cdm_data_loaders.readers.jsonlines ¶
JSONLines file reading utilities.
iter_file_jsonl_records ¶
Open file_item and yield parsed LineRecord dicts for each non-blank line.
dlt's default compression="auto" decompresses files that the listing marked as gzip, which it
does from the file name (*.gz) for every filesystem.
Source code in src/cdm_data_loaders/readers/jsonlines.py
stream_jsonl_lines ¶
stream_jsonl_lines(
items: Iterator[FileItemDict], buffer_size: int
) -> Generator[TDataItems, Any, Any]
Read each file in items. Yield pages of line records.
Each record has: record (parsed JSON, or None on parse failure),
raw_record, parse_error (None on success), source_file, line_no.
Records are accumulated into pages of buffer_size before being
yielded, so downstream transformers receive pages rather than
individual rows.
:yield: pages of line records
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterator[FileItemDict]
|
file items to read |
required |
buffer_size
|
int
|
number of line records per yielded page |
required |
Source code in src/cdm_data_loaders/readers/jsonlines.py
make_page_router ¶
make_page_router(
table_name: str,
buffer_size: int,
resolve_error: ParseErrorResolver | None = None,
*,
transform_valid: Callable[[Any], Any] | None = None,
table_transform: RecordTransformFn | None = None,
schema_map: ArrowSchemaRegistry | None = None,
use_pyarrow: bool = True
) -> Callable[
[Iterable[dict[str, Any]]], Generator[Any, Any, Any]
]
Build a function that routes pages of line records to valid and rejected tables.
For each item, resolve_error (when provided) inspects the record and
returns None for a valid record, or the error detail string otherwise.
Parse errors bypass resolve_error entirely. Valid records yield
item["record"] passed through transform_valid (identity when None) and
table_transform into target table(s); failed records yield a provenance
row (table_name, source_file, line_no, raw_record,
error_detail) into _rejected. Records are accumulated in a
DictBuffer, which emits _rejected and schematized target tables as
pyarrow.Table pages when use_pyarrow is True, or as list[dict]
pages otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
default table name for valid records |
required |
buffer_size
|
int
|
number of rows to buffer per table before yielding a page |
required |
resolve_error
|
ParseErrorResolver | None
|
optional function returning None for valid records or error detail |
None
|
transform_valid
|
Callable[[Any], Any] | None
|
function applied to each valid record before routing |
None
|
table_transform
|
RecordTransformFn | None
|
optional transform function for filtering, transforming, or splitting records |
None
|
schema_map
|
ArrowSchemaRegistry | None
|
optional per-table PyArrow schema registry |
None
|
use_pyarrow
|
bool
|
whether buffered pages are emitted as |
True
|
Returns:
| Type | Description |
|---|---|
Callable[[Iterable[dict[str, Any]]], Generator[Any, Any, Any]]
|
function taking one page (or iterable) of line records and yielding routed pages |
Source code in src/cdm_data_loaders/readers/jsonlines.py
route_jsonl_lines ¶
route_jsonl_lines(
items: Iterator[FileItemDict],
settings: JsonlExtractSettings,
) -> Generator[TDataItems, Any, Any]
Read each file in items and route each line by its file's table name.
Valid records yield into the file's table with the given name (or transformed
tables when table_transform is supplied).
Records that fail JSON parsing yield into _rejected with
table_name, source_file, line_no, raw_record, and error_detail.
:yield: table-tagged rows
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterator[FileItemDict]
|
file items to read |
required |
settings
|
JsonlExtractSettings
|
pipeline configuration |
required |