cdm_data_loaders.utils.buffer ¶
Buffer class for accumulating rows per table prior to yielding them to dlt.
dlt loads most efficiently when transformers and resources yield pages of rows
rather than individual items. DictBuffer accumulates parsed rows per table and
hands back full pages when a table's buffer reaches its size limit, converting pages
to pyarrow.Table instances for any table with a registered PyArrow schema
(including _rejected, which is registered by default).
DictBuffer
pydantic-model
¶
Bases: BaseModel
Accumulates rows per table and yields them as pages to dlt.
When use_pyarrow is True (the default), any table with a pyarrow.Schema in
schema_map (as well as _rejected, which uses REJECTED_PYARROW_SCHEMA) is yielded
as a pyarrow.Table; otherwise, pages are yielded as list[dict] as-is.
Config:
arbitrary_types_allowed:Trueextra:forbid
Fields:
-
max_items(MaxItems) -
schema_map(ArrowSchemaRegistry | None) -
use_pyarrow(bool)
Source code in src/cdm_data_loaders/utils/buffer.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 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 | |
from_settings
classmethod
¶
Construct a DictBuffer from pipeline settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Any
|
pipeline settings with |
required |
Returns:
| Type | Description |
|---|---|
Self
|
configured |
Source code in src/cdm_data_loaders/utils/buffer.py
flush ¶
Yield any remaining buffered rows as final pages and empty the buffers.
Source code in src/cdm_data_loaders/utils/buffer.py
add_item ¶
Add an item to a table. Yield a page if the table reaches max_items.
:yield: generator that yields collected rows to the appropriate dlt table
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
name of the table to add the item to |
required |
item_to_add
|
Any
|
the item |
required |
Source code in src/cdm_data_loaders/utils/buffer.py
add_items ¶
Add items to per-table buffers. Yield a page for any table that reaches max_items.
:yield: generator that yields collected rows to the appropriate dlt table(s)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items_to_add
|
dict[str, list[Any]]
|
dictionary of lists of items to add to per-table buffers, indexed by table name |
required |
Source code in src/cdm_data_loaders/utils/buffer.py
make_rejected_row ¶
make_rejected_row(
table_name: str | None,
error_detail: str,
*,
source_file: str | None = None,
line_no: int | None = None,
raw_record: str | None = None
) -> dict[str, Any]
Build a standardized row dictionary for the _rejected table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str | None
|
target table name associated with the rejected record |
required |
error_detail
|
str
|
human-readable error message |
required |
source_file
|
str | None
|
relative path or identifier of the source file |
None
|
line_no
|
int | None
|
1-based line number within the source file, if applicable |
None
|
raw_record
|
str | None
|
serialized raw record text, if applicable |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dictionary matching |
Source code in src/cdm_data_loaders/utils/buffer.py
make_rejected_table_result ¶
make_rejected_table_result(
table_name: str,
raw_record_obj: Mapping[str, Any],
error_detail: str,
*,
source_file: str | None = None,
line_no: int | None = None
) -> dict[str, list[dict[str, Any]]]
Build a {_rejected: [row]} result mapping for a record transform failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
source table name of the record that failed transformation |
required |
raw_record_obj
|
Mapping[str, Any]
|
input record mapping to serialize into |
required |
error_detail
|
str
|
human-readable error message |
required |
source_file
|
str | None
|
relative path or identifier of the source file |
None
|
line_no
|
int | None
|
1-based line number within the source file, if applicable |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, list[dict[str, Any]]]
|
single-row |
Source code in src/cdm_data_loaders/utils/buffer.py
make_dict_buffer ¶
make_dict_buffer(
settings: Any,
buffer_cls: Callable[..., DictBuffer] = DictBuffer,
) -> DictBuffer
Construct a DictBuffer from pipeline settings using buffer_cls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Any
|
pipeline settings with |
required |
buffer_cls
|
Callable[..., DictBuffer]
|
|
DictBuffer
|
Returns:
| Type | Description |
|---|---|
DictBuffer
|
configured |