atoti.MultiRowArrayConversion#

class atoti.MultiRowArrayConversion#

Convert an external table where array values are stored with one value per row to a table with array columns.

The external table must have an index_column and at least one “value” column representing the array elements.

All the table columns except from index_column and the array_columns will become key columns.

Example

>>> external_database = session.connect_to_external_database(connection_info)
>>> external_table = external_database.tables["TUTORIAL", "MULTI_ROW_QUANTITY"]

external_table has an INDEX column:

>>> external_table.columns
['PRODUCT', 'INDEX', 'QUANTITY']

and its content is:

PRODUCT

INDEX

QUANTITY

product_1

0

10.0

product_1

1

20.0

product_1

2

15.0

product_1

3

25.0

product_1

4

10.0

product_2

0

50.0

product_2

1

65.0

product_2

2

55.0

product_2

3

30.0

product_2

4

80.0

It can be converted into a table with an array column:

>>> from atoti_directquery_snowflake import SnowflakeTableOptions
>>> table = session.add_external_table(
...     external_table,
...     table_name="Sales (Multi row array)",
...     options=SnowflakeTableOptions(
...         array_conversion=tt.MultiRowArrayConversion(
...             index_column="INDEX",
...             array_columns={"QUANTITY"},
...         ),
...     ),
... )
>>> table.head().sort_index()
                                 QUANTITY
PRODUCT
product_1  [10.0, 20.0, 15.0, 25.0, 10.0]
product_2  [50.0, 65.0, 55.0, 30.0, 80.0]
array_columns: Set[str] | Sequence[str]#

Names of the columns that contain array values.

index_column: str#

Name of the column used as an index for the arrays.