cdm_data_loaders.readers.jsonschema_xsv.xsv_reader ¶
Reader for XSV data cleaned and validated by xsv_validator.qsv.
Reads rows from a file produced by xsv_validator.qsv.clean_validate_file, casting each field
to the type declared for it in the target PyArrow schema. Also resolves the
qsv cleaning/validation parameters (delimiter, quote, escape, comment character, null handling)
from a schema's x-xsv-config extension block.
resolve_xsv_parsing_config ¶
Derive CleanerValidatorArgs kwargs from a schema's x-xsv-config extension block.
Schemas without an x-xsv-config block resolve to an empty dict, letting
CleanerValidatorArgs fall back to its own defaults (tab-delimited, #-commented, header
present).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validated_schema
|
ValidatedXsvSchema
|
parsed, validated JSON Schema for the XSV data |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
kwargs accepted by |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_reader.py
resolve_duckdb_column_config ¶
Derive DuckDB CSV reader column-type and nullability kwargs from a PyArrow schema.
Maps each field in pa_schema to a DuckDBPyType via duckdb.from_arrow. Columns absent
from pa_schema default to nullable VARCHAR via auto_type_candidates=["VARCHAR"].
Non-nullable string columns are listed in force_not_null so empty cells remain ""
rather than None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pa_schema
|
Schema | None
|
target PyArrow schema for the XSV table, or |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
kwargs ( |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_reader.py
read_validated_rows ¶
read_validated_rows(
xsv_path: Path,
pa_schema: Schema | None = None,
delimiter: str = "\t",
quote: str | None = None,
escape: str | None = None,
*,
chunk_size: int = DEFAULT_BUFFER_MAX_ITEMS,
use_pyarrow: bool = False
) -> Generator[dict[str, Any] | pa.Table, Any, Any]
Read a cleaned, validated XSV file via read_csv_duckdb, coercing columns to schema types on read.
The file is expected to carry a header row matching the schema's column names, as produced
by xsv_validator.qsv.clean_validate_file. When use_pyarrow is True, yields pa.Table
chunks (aligned to pa_schema when provided); when False, yields row dicts.
:yield: row dicts (when use_pyarrow=False) or pa.Table chunks (when use_pyarrow=True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xsv_path
|
Path
|
path to the cleaned, validated XSV file |
required |
pa_schema
|
Schema | None
|
optional target PyArrow schema used to configure DuckDB column types and align |
None
|
delimiter
|
str
|
delimiter used in the file, defaults to tab |
'\t'
|
quote
|
str | None
|
quote character used in the file; defaults to |
None
|
escape
|
str | None
|
escape character used in the file; when unset, quotes are escaped by doubling |
None
|
chunk_size
|
int
|
maximum number of rows per DuckDB batch |
DEFAULT_BUFFER_MAX_ITEMS
|
use_pyarrow
|
bool
|
when True, yield |
False
|