> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AutoMultiColumnArrayConversion

<span id="atoti.AutoMultiColumnArrayConversion" />

> atoti.AutoMultiColumnArrayConversion(<br />
>     \*,<br />
>     *separator*: [str](https://docs.python.org/3/library/stdtypes.html#str) = `''`,<br />
>     *threshold*: [int](https://docs.python.org/3/library/functions.html#int) = `50`,<br />
> )

Pass it to a DirectQuery `*ConnectionConfig` class to automatically convert all external tables with array values stored with one element per column to tables with array columns.

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> import os
>>> from atoti_directquery_snowflake import ConnectionConfig, TableConfig
>>> url = f"jdbc:snowflake://{os.environ['SNOWFLAKE_ACCOUNT_IDENTIFIER']}.snowflakecomputing.com/?user={os.environ['SNOWFLAKE_USERNAME']}&database=TEST_RESOURCES&schema=TESTS"
>>> connection_config = ConnectionConfig(
...     url=url,
...     auto_multi_column_array_conversion=tt.AutoMultiColumnArrayConversion(
...         separator="_",
...         threshold=3,
...     ),
...     password=os.environ["SNOWFLAKE_PASSWORD"],
... )
>>> external_database = session.connect_to_external_database(connection_config)
>>> external_table = external_database.tables["TUTORIAL", "MULTI_COLUMN_QUANTITY"]
```

In the external database, `external_table` has this content:

| PRODUCT    | QUANTITY\_0 | QUANTITY\_1 | QUANTITY\_2 | QUANTITY\_3 | QUANTITY\_4 |
| ---------- | ----------- | ----------- | ----------- | ----------- | ----------- |
| product\_1 | 10          | 20          | 15          | 25          | 10          |
| product\_2 | 50          | 65          | 55          | 30          | 80          |

It has 5 `QUANTITY{separator}{index}` columns (where [`separator`](#atoti.AutoMultiColumnArrayConversion.separator) is `"_"`).
Since 5 is greater than the [`threshold`](#atoti.AutoMultiColumnArrayConversion.threshold) passed above, the automatic conversion will activate and these 5 columns will be merged into an array column:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> list(external_table)
['PRODUCT', 'QUANTITY']
>>> table = session.add_external_table(
...     external_table,
...     config=TableConfig(keys={"PRODUCT"}),
...     table_name="Sales (Multi column array)",
... )
>>> 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]
```

<Callout icon="link">
  **See also**:
  [`MultiColumnArrayConversion`](./atoti.directquery.array_conversion.MultiColumnArrayConversion#atoti.MultiColumnArrayConversion).
</Callout>

### Attributes

<h4 id="atoti.AutoMultiColumnArrayConversion.separator">
  *separator*
</h4>

The characters separating the array column name and the element index.

<h4 id="atoti.AutoMultiColumnArrayConversion.threshold">
  *threshold*
</h4>

The minimum number of columns with the same prefix required to trigger the automatic conversion.
