Module load.table in plugin tabular v0.5.1
| Author(s) | Markus Binsteiner (markus@frkl.io) |
| Tags | tabular |
| Python class | kiara_plugin.tabular.modules.table.DeserializeTableModule |
Module configuration options
Configuration class: kiara.modules.included_core_modules.serialization.SerializeConfig
| Name | Description | Type | Required? | Default |
|---|---|---|---|---|
| serialization_profile | The name of the serialization profile used to serialize the source value. | string | true | null |
| target_profile | The profile name of the de-serialization result data. | string | true | null |
| value_type | The value type of the actual (unserialized) value. | string | true | null |
| constants | Value constants for this module. | object | false | null |
| defaults | Value defaults for this module. | object | false | null |
Module source code
class DeserializeTableModule(DeserializeValueModule):
_module_type_name = "load.table"
@classmethod def retrieve_supported_target_profiles(cls) -> Mapping[str, Type]: return {"python_object": KiaraTable}
@classmethod def retrieve_serialized_value_type(cls) -> str: return "table"
@classmethod def retrieve_supported_serialization_profile(cls) -> str: return "feather"
def to__python_object(self, data: SerializedData, **config: Any):
import pyarrow as pa
columns = {}
table_schema_chunks = data.get_serialized_data(TABLE_SCHEMA_CHUNKS_NAME) chunks_generator = table_schema_chunks.get_chunks(as_files=False) schema_chunk = next(chunks_generator) # type: ignore schema = pa.ipc.read_schema(pa.py_buffer(schema_chunk))
for column_name in data.get_keys():
if column_name == TABLE_SCHEMA_CHUNKS_NAME: continue
chunks = data.get_serialized_data(column_name)
# TODO: support multiple chunks assert chunks.get_number_of_chunks() == 1 files = list(chunks.get_chunks(as_files=True, symlink_ok=True)) assert len(files) == 1
file = files[0] with pa.memory_map(file, "r") as column_chunk: loaded_arrays: pa.Table = pa.ipc.open_file(column_chunk).read_all() column = loaded_arrays.column(column_name) if column_name == EMPTY_COLUMN_NAME_MARKER: columns[""] = column else: columns[column_name] = column
arrow_table = pa.table(columns, schema=schema)
table = KiaraTable.create_table(arrow_table) return table