atoti.Session.add_external_table()#

Session.add_external_table(external_table, /, table_name=None, *, columns={}, options=None)#

Add a table from an external database to the session.

Parameters:
  • external_table (ExternalTableT_co) – The external database table from which to build the session table. Instances of such tables are obtained through an external database connection.

  • table_name (str | None) – The name to give to the table in the session. If None, the name of the external table is used.

  • columns (Mapping[str, str]) – Mapping from external column names to local column names. If empty, the local columns will share the names of the external columns.

  • options (ExternalTableOptions[ExternalTableT_co] | None) – The database specific options to read the table. Each DirectQuery plugin has its own *TableOptions class.

Return type:

Table

Example

>>> from atoti_directquery_snowflake import SnowflakeTableOptions
>>> external_database = session.connect_to_external_database(
...     connection_info
... )
>>> external_table = external_database.tables["TUTORIAL", "SALES"]
>>> external_table.columns
['SALE_ID', 'DATE', 'SHOP', 'PRODUCT', 'QUANTITY', 'UNIT_PRICE']

Add the external table, filtering out some columns and renaming the remaining ones:

>>> table = session.add_external_table(
...     external_table,
...     table_name="sales_renamed",
...     columns={"SALE_ID": "Sale ID", "DATE": "Date", "PRODUCT": "Product", "QUANTITY": "Quantity"},
...     options=SnowflakeTableOptions(keys=["Sale ID"]),
... )
>>> table.head().sort_index()
              Date Product  Quantity
Sale ID
S0007   2022-02-01   BED_2       1.0
S0008   2022-01-31   BED_2       1.0
S0009   2022-01-31   BED_2       1.0
S0010   2022-01-31   BED_2       3.0
S0019   2022-02-02   HOO_5       1.0