cdm_data_loaders.converters.facades.jsonschema_to_pyarrow ¶
Convert JSON Schema through the shared reader and PyArrow emitter.
JSONSchemaToPyArrowError ¶
Bases: ConversionError
Raised when a JSON Schema construct cannot be converted.
Subclasses raised by :func:generate_pyarrow_schema carry a stable specification code and a short
title; their docstrings state why the construct is rejected. The converter specification document is
generated from these attributes.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
InvalidJSONSchemaError ¶
Bases: JSONSchemaToPyArrowError
Raised when the input document is not a valid JSON Schema.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
UnsupportedDialectError ¶
Bases: InvalidJSONSchemaError
Only JSON Schema Draft 2020-12 and the KBase Draft 2020-12 XSV metaschema are supported.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
NonStructRootError ¶
Bases: JSONSchemaToPyArrowError
A pa.Schema needs top-level columns, so the root must resolve to a fixed-property object.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
EmptyObjectError ¶
Bases: JSONSchemaToPyArrowError
Parquet cannot store a pa.struct([]) with no child fields.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
UnconstrainedSchemaError ¶
Bases: JSONSchemaToPyArrowError
An untyped JSON value cannot be assigned a concrete Arrow DataType.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
OpenTupleError ¶
Bases: JSONSchemaToPyArrowError
A field cannot be both a positional pa.struct and an unbounded pa.list_.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
MixedPropertiesAndMapError ¶
Bases: JSONSchemaToPyArrowError
An object cannot be both a fixed-field pa.struct and a dynamic pa.map_.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
NegationError ¶
Bases: JSONSchemaToPyArrowError
A complement type does not define a positive storage DataType.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
IncompatibleBranchShapesError ¶
Bases: JSONSchemaToPyArrowError
Branches with different structural shapes (object vs array, array vs scalar, object vs map) cannot share one column.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
UnsupportedRefError ¶
Bases: JSONSchemaToPyArrowError
Every $ref must resolve to a local #/$defs/... definition; $dynamicRef and $recursiveRef are not supported.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
RecursiveNonJsonTypeError ¶
Bases: JSONSchemaToPyArrowError
Truncated recursive subtrees are serialized with json.dumps, which cannot encode datetime.date or bytes.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
NullOnlySchemaError ¶
Bases: JSONSchemaToPyArrowError
Parquet has no physical storage type for a pa.null() column.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
ValueFieldCollisionError ¶
Bases: JSONSchemaToPyArrowError
The synthesized _value field of a scalar + object union would collide with a declared _value property.
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
JSONSchemaToPyArrow
pydantic-model
¶
Bases: JsonSchemaConverterBase[Schema]
Read Draft 2020-12 JSON Schema through the shared IR reader and emit PyArrow schemas and empty tables.
Fields:
-
extension_registry(InstanceOf[ExtensionRegistry]) -
max_recursion_depth(int) -
format_map(frozendict[str, DataType]) -
treat_unknown_as_string(bool) -
emit_unions_as_json(bool) -
extra_metadata_keywords(ExtraMetadataKeywords) -
max_nesting(PositiveInt)
Validators:
-
_merge_with_builtin_format_map→format_map
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
convert_to_table ¶
Convert a Draft 2020-12 JSON Schema object document to an empty Arrow table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
the JSON Schema, which must declare |
required |
Returns:
| Type | Description |
|---|---|
pa.Table
|
a zero-row table with the converted schema |
Raises:
| Type | Description |
|---|---|
InvalidJSONSchemaError
|
if |
JSONSchemaToPyArrowError
|
if the root is not an object or a construct cannot be converted |
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
convert_to_python ¶
Convert a Draft 2020-12 JSON Schema object document to a static Python schema module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
the JSON Schema, which must declare |
required |
docstring
|
str | None
|
optional module docstring header |
None
|
Returns:
| Type | Description |
|---|---|
str
|
formatted Python source code defining |
Raises:
| Type | Description |
|---|---|
InvalidJSONSchemaError
|
if |
JSONSchemaToPyArrowError
|
if the root is not an object or a construct cannot be converted |
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
convert_to_python_file ¶
convert_to_python_file(
schema: dict[str, Any],
output: str | Path,
*,
docstring: str | None = None
) -> Path
Convert a Draft 2020-12 JSON Schema object document and write a static Python schema module to output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
the JSON Schema, which must declare |
required |
output
|
str | Path
|
destination file path for the generated Python module |
required |
docstring
|
str | None
|
optional module docstring header |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
resolved output |
Raises:
| Type | Description |
|---|---|
InvalidJSONSchemaError
|
if |
JSONSchemaToPyArrowError
|
if the root is not an object or a construct cannot be converted |
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
resolve_scalar_type ¶
Map a scalar JSON Schema node to its PyArrow type and jsonschema_type label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Mapping[str, Any]
|
scalar schema node ( |
required |
Returns:
| Type | Description |
|---|---|
tuple[pa.DataType, str]
|
|
Raises:
| Type | Description |
|---|---|
JSONSchemaToPyArrowError
|
if |
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
generate_pyarrow_schema ¶
generate_pyarrow_schema(
schema: dict[str, Any],
*,
max_recursion_depth: int = DEFAULT_MAX_RECURSION_DEPTH
) -> pa.Schema
Generate a deterministic PyArrow Schema from a Draft 2020-12 JSON Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
JSON Schema Draft 2020-12 dictionary |
required |
max_recursion_depth
|
int
|
maximum expansion depth for recursive |
DEFAULT_MAX_RECURSION_DEPTH
|
Returns:
| Type | Description |
|---|---|
pa.Schema
|
PyArrow schema with top-level fields corresponding to root object properties |
Raises:
| Type | Description |
|---|---|
JSONSchemaToPyArrowError
|
if |
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
convert_schema_to_pyarrow ¶
Dereference a validated JSON Schema and convert it to a PyArrow schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
ValidatedSchema
|
validated JSON Schema |
required |
Returns:
| Type | Description |
|---|---|
pa.Schema
|
target PyArrow schema for the entity table |
Raises:
| Type | Description |
|---|---|
DereferencingError
|
if |
JSONSchemaToPyArrowError
|
if the dereferenced schema cannot be converted to a PyArrow schema |
Source code in src/cdm_data_loaders/converters/facades/jsonschema_to_pyarrow.py
convert_xsv_schema_to_pyarrow ¶
Convert a validated XSV JSON Schema to a PyArrow schema.
In XSV schemas, top-level required declares the ordered CSV columns,
unlisted columns default to nullable strings, and any column whose
schema permits null is nullable in PyArrow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validated_schema
|
ValidatedXsvSchema
|
validated XSV JSON Schema |
required |
Returns:
| Type | Description |
|---|---|
pa.Schema
|
PyArrow schema for the XSV table |