cdm_data_loaders.converters.facades.pyarrow_to_jsonschema ¶
Convert PyArrow schemas, fields, and data types to Draft 2020-12 JSON Schema documents.
PyArrowToJSONSchemaError ¶
Bases: ConversionError
Raised when a PyArrow schema, field, or data type cannot be converted to JSON Schema.
Subclasses raised by :func:generate_json_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/pyarrow_to_jsonschema.py
InvalidPyArrowSchemaError ¶
Bases: PyArrowToJSONSchemaError
Schema generation requires a concrete PyArrow pa.Schema object; bare pa.DataType, pa.Field, or Python mappings are not table schemas.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
EmptyStructError ¶
Bases: PyArrowToJSONSchemaError
Arrow tables and Parquet struct columns require at least one named child field.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
DuplicateFieldNameError ¶
Bases: PyArrowToJSONSchemaError
JSON Schema properties is an object mapping keyed by property name and cannot represent duplicate sibling field names.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
NullOnlyTypeError ¶
Bases: PyArrowToJSONSchemaError
A column or container element typed solely as pa.null() carries no value domain; nullable columns must wrap a concrete Arrow value type with nullable=True.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
InvalidDecimalTypeError ¶
Bases: PyArrowToJSONSchemaError
Fixed-point decimal string patterns require 0 <= scale <= precision; negative scales or scale > precision have no plain fixed-point string regex.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
UnsupportedTemporalIntervalError ¶
Bases: PyArrowToJSONSchemaError
Relative durations and month_day_nano intervals have no lossless canonical scalar representation across JSON Schema validators without losing unit or sign-per-component semantics.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
UnsupportedUnionTypeError ¶
Bases: PyArrowToJSONSchemaError
Arrow type-code unions lack stable JSON property discriminators and Parquet storage support; union columns must be normalized before schema export.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
UnsupportedArrowTypeError ¶
Bases: PyArrowToJSONSchemaError
Specialized physical encodings such as pa.run_end_encoded and custom pa.ExtensionType subclasses have no general target-independent JSON Schema contract.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
PyArrowToJSONSchema
pydantic-model
¶
Bases: BaseModel
Frozen facade converting PyArrow pa.Schema objects to Draft 2020-12 JSON Schema documents.
Config:
arbitrary_types_allowed:Truefrozen:True
Fields:
-
schema_name(str | None) -
schema_id(str | None) -
include_pyarrow_metadata(bool) -
extension_registry(InstanceOf[ExtensionRegistry])
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
convert ¶
Convert a PyArrow pa.Schema into a Draft 2020-12 JSON Schema dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow schema. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Rendered JSON Schema dictionary. |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
convert_into ¶
Convert schema and insert it under destination["$defs"][<name>].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow schema. |
required |
destination
|
dict[str, Any]
|
Namespace JSON Schema dictionary to populate. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Updated |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
convert_to_json ¶
Convert a PyArrow pa.Schema into a formatted JSON Schema string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow schema. |
required |
indent
|
int
|
JSON indentation spaces (default |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted JSON string with trailing newline. |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
convert_to_json_file ¶
Convert a PyArrow pa.Schema and write the resulting JSON Schema to output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow schema. |
required |
output
|
str | Path
|
Destination file path. |
required |
indent
|
int
|
JSON indentation spaces (default |
2
|
Returns:
| Type | Description |
|---|---|
Path
|
Resolved output |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
convert_type ¶
convert_type(
dtype: DataType,
*,
nullable: bool = False,
include_pyarrow_metadata: bool = True,
extension_registry: ExtensionRegistry = DEFAULT_EXTENSIONS
) -> dict[str, Any]
Convert a standalone PyArrow DataType into a Draft 2020-12 JSON Schema subschema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
DataType
|
PyArrow data type to convert. |
required |
nullable
|
bool
|
Whether to wrap the subschema in a nullable |
False
|
include_pyarrow_metadata
|
bool
|
Whether to include |
True
|
extension_registry
|
ExtensionRegistry
|
Registry for extension validation. |
DEFAULT_EXTENSIONS
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Rendered JSON Schema dictionary. |
Raises:
| Type | Description |
|---|---|
PyArrowToJSONSchemaError
|
If |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
resolve_scalar_type ¶
resolve_scalar_type(
dtype: DataType,
*,
include_pyarrow_metadata: bool = True,
extension_registry: ExtensionRegistry = DEFAULT_EXTENSIONS
) -> dict[str, Any]
Resolve a scalar (or dictionary-encoded scalar) PyArrow DataType to its JSON Schema fragment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
DataType
|
Scalar PyArrow data type. |
required |
include_pyarrow_metadata
|
bool
|
Whether to include |
True
|
extension_registry
|
ExtensionRegistry
|
Registry for extension validation. |
DEFAULT_EXTENSIONS
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Rendered JSON Schema dictionary for |
Raises:
| Type | Description |
|---|---|
PyArrowToJSONSchemaError
|
If |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
convert_field ¶
convert_field(
pa_field: Field,
*,
include_pyarrow_metadata: bool = True,
extension_registry: ExtensionRegistry = DEFAULT_EXTENSIONS
) -> dict[str, Any]
Convert a PyArrow Field into a JSON Schema property subschema with nullability and field metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pa_field
|
Field
|
PyArrow field to convert. |
required |
include_pyarrow_metadata
|
bool
|
Whether to include |
True
|
extension_registry
|
ExtensionRegistry
|
Registry for extension validation. |
DEFAULT_EXTENSIONS
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Rendered JSON Schema property dictionary. |
Raises:
| Type | Description |
|---|---|
PyArrowToJSONSchemaError
|
If |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_jsonschema.py
generate_json_schema ¶
generate_json_schema(
schema: Schema,
*,
schema_name: str | None = None,
schema_id: str | None = None,
include_pyarrow_metadata: bool = True,
destination: dict[str, Any] | None = None
) -> dict[str, Any]
Generate a Draft 2020-12 JSON Schema document from a PyArrow pa.Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow table schema. |
required |
schema_name
|
str | None
|
Optional schema |
None
|
schema_id
|
str | None
|
Optional schema |
None
|
include_pyarrow_metadata
|
bool
|
Whether to emit |
True
|
destination
|
dict[str, Any] | None
|
Optional namespace JSON Schema document to populate under |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Draft 2020-12 JSON Schema dictionary, or |
Raises:
| Type | Description |
|---|---|
PyArrowToJSONSchemaError
|
If |