Skip to content

tables

Attributes

Classes

KiaraTables

Bases: KiaraModel

A wrapper class, containing multiple tables.

Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/kiara_plugin/tabular/models/tables.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class KiaraTables(KiaraModel):
    """A wrapper class, containing multiple tables."""

    @classmethod
    def create_tables(cls, data: Any) -> "KiaraTables":

        if isinstance(data, KiaraTables):
            return data

        table_obj: Union[None, Dict[str, KiaraTable]] = None
        if isinstance(data, Mapping):
            temp = {}
            for k, v in data.items():
                temp[k] = KiaraTable.create_table(v)
            table_obj = temp

        elif isinstance(data, (pa.Table)):
            table_obj = {DEFAULT_TABLE_NAME: data}

        if table_obj is None:
            raise Exception(
                f"Can't create tables, invalid source data type: {type(data)}."
            )

        obj = cls(tables=table_obj)
        return obj

    tables: Dict[str, KiaraTable] = Field(
        description="A dictionary of tables, with the table names as keys."
    )

    @property
    def table_names(self) -> List[str]:
        return list(self.tables.keys())

    def _retrieve_data_to_hash(self) -> Any:
        raise NotImplementedError()

    def get_table(self, table_name: str) -> KiaraTable:

        if table_name not in self.tables:
            raise KiaraException(
                f"Table '{table_name}' not found. Available: {', '.join(self.tables.keys())}"
            )

        return self.tables[table_name]

Attributes

tables: Dict[str, KiaraTable] = Field(description='A dictionary of tables, with the table names as keys.') class-attribute instance-attribute
table_names: List[str] property

Functions

create_tables(data: Any) -> KiaraTables classmethod
Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/kiara_plugin/tabular/models/tables.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@classmethod
def create_tables(cls, data: Any) -> "KiaraTables":

    if isinstance(data, KiaraTables):
        return data

    table_obj: Union[None, Dict[str, KiaraTable]] = None
    if isinstance(data, Mapping):
        temp = {}
        for k, v in data.items():
            temp[k] = KiaraTable.create_table(v)
        table_obj = temp

    elif isinstance(data, (pa.Table)):
        table_obj = {DEFAULT_TABLE_NAME: data}

    if table_obj is None:
        raise Exception(
            f"Can't create tables, invalid source data type: {type(data)}."
        )

    obj = cls(tables=table_obj)
    return obj
get_table(table_name: str) -> KiaraTable
Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/kiara_plugin/tabular/models/tables.py
56
57
58
59
60
61
62
63
def get_table(self, table_name: str) -> KiaraTable:

    if table_name not in self.tables:
        raise KiaraException(
            f"Table '{table_name}' not found. Available: {', '.join(self.tables.keys())}"
        )

    return self.tables[table_name]

KiaraTablesMetadata

Bases: ValueMetadata

File stats.

Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/kiara_plugin/tabular/models/tables.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class KiaraTablesMetadata(ValueMetadata):
    """File stats."""

    _metadata_key = "tables"

    @classmethod
    def retrieve_supported_data_types(cls) -> Iterable[str]:
        return ["tables"]

    @classmethod
    def create_value_metadata(cls, value: "Value") -> "KiaraTablesMetadata":

        kiara_tables: KiaraTables = value.data

        tables = {}
        for table_name, table in kiara_tables.tables.items():

            md = TableMetadata.create_from_table(table)
            tables[table_name] = md

        return KiaraTablesMetadata.construct(tables=tables)

    tables: Dict[str, TableMetadata] = Field(description="The table schema.")

Attributes

tables: Dict[str, TableMetadata] = Field(description='The table schema.') class-attribute instance-attribute

Functions

retrieve_supported_data_types() -> Iterable[str] classmethod
Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/kiara_plugin/tabular/models/tables.py
71
72
73
@classmethod
def retrieve_supported_data_types(cls) -> Iterable[str]:
    return ["tables"]
create_value_metadata(value: Value) -> KiaraTablesMetadata classmethod
Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/kiara_plugin/tabular/models/tables.py
75
76
77
78
79
80
81
82
83
84
85
86
@classmethod
def create_value_metadata(cls, value: "Value") -> "KiaraTablesMetadata":

    kiara_tables: KiaraTables = value.data

    tables = {}
    for table_name, table in kiara_tables.tables.items():

        md = TableMetadata.create_from_table(table)
        tables[table_name] = md

    return KiaraTablesMetadata.construct(tables=tables)