cdm_data_loaders.core.transforms ¶
Pluggable record filtering, transformation, multi-table splitting, and PyArrow schema overrides.
TransformSettingsMixin ¶
Bases: BaseSettings
Mixin for pipelines that accept FILE_PREPROCESSORS, TABLE_TRANSFORMS, and OUTPUT_SCHEMAS modules.
Source code in src/cdm_data_loaders/core/transforms.py
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 247 248 249 250 251 252 253 254 255 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 | |
use_pyarrow
property
¶
Return whether this pipeline yields pyarrow.Table pages instead of row dicts.
file_preprocessors
property
¶
The loaded FILE_PREPROCESSORS registry (None if not configured).
table_transforms
property
¶
The loaded TABLE_TRANSFORMS registry (None if not configured).
schema_map
property
¶
The resolved ArrowSchemaRegistry for this pipeline (None if unschematized).
get_file_preprocessors ¶
Return the FilePreprocessFn sequence for table_name, if configured.
Source code in src/cdm_data_loaders/core/transforms.py
get_table_transform ¶
Return the RecordTransformFn for table_name, if configured.
Source code in src/cdm_data_loaders/core/transforms.py
resolve_schema_map ¶
resolve_schema_map(
default_table: str,
*,
transform: RecordTransformFn | None = None,
unreconciled_output_schemas: (
ArrowSchemaRegistry | None
) = None,
default_pyarrow_schema: Schema | None = None
) -> ArrowSchemaRegistry | None
Resolve the active table-to-PyArrow-schema registry for a reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default_table
|
str
|
default target table name for the pipeline/entity |
required |
transform
|
RecordTransformFn | None
|
optional |
None
|
unreconciled_output_schemas
|
ArrowSchemaRegistry | None
|
optional |
None
|
default_pyarrow_schema
|
Schema | None
|
default PyArrow schema when no override is configured |
None
|
Returns:
| Type | Description |
|---|---|
ArrowSchemaRegistry | None
|
|
Source code in src/cdm_data_loaders/core/transforms.py
validate_routed_output ¶
Validate the return value of transform_fn and strip empty table lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_routed
|
object
|
raw output from |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[dict[str, Any]]]
|
validated dictionary mapping destination table names to non-empty lists of row dictionaries |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in src/cdm_data_loaders/core/transforms.py
route_and_coerce_record ¶
route_and_coerce_record(
record: dict[str, Any],
default_table: str,
*,
transform: RecordTransformFn | None = None,
schema_map: ArrowSchemaRegistry | None = None
) -> dict[str, list[dict[str, Any]]]
Route a validated record through transform and optionally coerce rows for PyArrow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
dict[str, Any]
|
parsed and validated input record dictionary |
required |
default_table
|
str
|
destination table name when |
required |
transform
|
RecordTransformFn | None
|
optional |
None
|
schema_map
|
ArrowSchemaRegistry | None
|
active destination |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, list[dict[str, Any]]]
|
dictionary mapping destination table names to non-empty lists of row dictionaries |
Source code in src/cdm_data_loaders/core/transforms.py
validate_table_transforms ¶
Ensure every key in settings.table_transforms matches a configured input table.
Source code in src/cdm_data_loaders/core/transforms.py
uses_pyarrow_format ¶
Return whether settings.loader_file_format is a PyArrow-backed loader format.
Source code in src/cdm_data_loaders/core/transforms.py
needs_default_pyarrow_schema ¶
needs_default_pyarrow_schema(
table_name: str,
*,
use_pyarrow: bool = True,
table_transforms: TransformRegistry | None = None,
output_schemas: ArrowSchemaRegistry | None = None
) -> bool
Return whether table_name needs its PyArrow schema generated from the input schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
target table name |
required |
use_pyarrow
|
bool
|
whether PyArrow output is enabled |
True
|
table_transforms
|
TransformRegistry | None
|
optional configured table transforms registry |
None
|
output_schemas
|
ArrowSchemaRegistry | None
|
optional user-supplied output schemas registry |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|