atoti.Session.create_table()#

Session.create_table(name, *, types, keys=(), partitioning=None, default_values={}, **kwargs)#

Create a table from a schema.

Parameters:
  • name (str) – The name of the table to create.

  • types (Mapping[str, DataType]) –

    Types for all columns of the table. This defines the columns which will be expected in any future data loaded into the table.

    See also

    atoti.type for data type constants.

  • keys (Collection[str]) –

    The columns that will become keys of the table.

    Inserting a row containing key values equal to the ones of an existing row will replace the existing row with the new one.

    Key columns cannot have None as their default_value.

  • partitioning (str | None) –

    The description of how the data will be split across partitions of the table.

    Default rules:

    • Only non-joined tables are automatically partitioned.

    • Tables are automatically partitioned by hashing their key columns. If there are no key columns, all the dictionarized columns are hashed.

    • Joined tables can only use a sub-partitioning of the table referencing them.

    • Automatic partitioning is done modulo the number of available cores.

    Example

    hash4(country) splits the data across 4 partitions based on the country column’s hash value.

  • default_values (Mapping[str, ConstantValue | None]) – Mapping from column name to column default_value.

Return type:

Table

Example

>>> from datetime import date
>>> table = session.create_table(
...     "Product",
...     types={"Date": tt.LOCAL_DATE, "Product": tt.STRING, "Quantity": tt.DOUBLE},
...     keys=["Date", "Product"],
... )
>>> table.head()
Empty DataFrame
Columns: [Quantity]
Index: []
>>> table.append(
...     (date(2021, 5, 19), "TV", 15.0),
...     (date(2022, 8, 17), "Car", 2.0),
... )
>>> table.head()
                    Quantity
Date       Product
2021-05-19 TV           15.0
2022-08-17 Car           2.0

Inserting a row with the same key values as an existing row replaces the latter:

>>> table += (date(2021, 5, 19), "TV", 8.0)
>>> table.head()
                    Quantity
Date       Product
2021-05-19 TV            8.0
2022-08-17 Car           2.0