mstrio > modeling > schema > table > warehouse_table¶
- class mstrio.modeling.schema.table.warehouse_table.WarehouseTable(id, connection, datasource, namespace_id, name, namespace)¶
Bases:
Dictable
An object representation of a warehouse table. Depending on whether a warehouse table is included in a project, it may or may not have a persistent id and associated PhysicalTable object. When you add a warehouse table to a project, a MSTR server will create a PhysicalTable object that represents the added warehouse table and will assign it a persistent ID. You can then manipulate the table further using functionalities in mstrio.modeling.schema.table.physical_table.
- Parameters:
id (str) –
connection (Connection) –
datasource (DatasourceInstance) –
namespace_id (str) –
name (str) –
namespace (str) –
- connection¶
An object representation of MSTR Connection.
- Type:
- datasource¶
An object representation of datasource instance in which the table resides.
- Type:
- name¶
A name of the table.
- Type:
str
- namespace¶
A name of a namespace in which the table resides.
- Type:
str
- namespace_id¶
An ID of a namespace in which the table resides.
- Type:
str
- physical_table_id¶
An ID of an associated PhysicalTable object. This attribute is set automatically after add_to_project() method was called on the table.
- Type:
str
- dependent_logical_tables¶
A list of logical tables that are mapped to the warehouse table.
- Type:
Union[list[dict], list[LogicalTable]]
- columns¶
A list of table columns.
- Type:
Union[list[dict], list[TableColumn]]
- add_to_project(logical_table_name, prefix=None, col_merge_option=None)¶
- Adds a table to a project. This function corresponds to ‘ADD WHTABLE’
statement from MSTR Command Manager.
- Parameters:
logical_table_name (str) – Name of the logical table which will be mapped to this warehouse table.
prefix (Optional[str], optional) – Table prefix. Defaults to None.
(Optional[Union[TableColumnMergeOption (col_merge_option) – Defines a column merge option. Defaults to None.
str]] – Defines a column merge option. Defaults to None.
col_merge_option (TableColumnMergeOption | str | None) –
- Returns:
- A LogicalTable object representing a logical table
mapped to this warehouse table.
- Return type:
- classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)¶
Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of the objects that should be created.
source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
A list of objects of type T.
- Return type:
T
- delete_from_project(force=False)¶
Remove the Warehouse Table from a project by removing all of its dependent logical tables. It will only delete dependent logical tables if they themselves have no dependent objects. This function corresponds to “REMOVE WHTABLE” statement from MSTR Command Manager.
- Parameters:
force (bool) –
- Return type:
list[bool] | None
- classmethod from_dict(source, connection=None, to_snake_case=True, with_missing_value=False)¶
Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of an object that should be created.
source (Dict[str, Any]) – A dictionary from which an object will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
An object of type T.
- Return type:
T
- list_columns(to_dictionary=False, refresh=False)¶
Get columns for a specific database table.
- Parameters:
to_dictionary (bool, optional) – If True, returns a list of dictionaries. Defaults to False.
refresh (bool, optional) – If True, refetches and overwrites the cached version of results stored in WarehouseTable.columns.
- Returns:
- A list of TableColumn objects
or dictionaries representing table columns.
- Return type:
Union[list[TableColumn], list[dict]]
- list_dependent_logical_tables(to_dictionary=False, refresh=False)¶
Get all dependent logical tables.
- Parameters:
to_dictionary (bool, optional) – If True, returns a list of dictionaries. Defaults to False.
refresh (bool, optional) – If True, refreshes the result stored in self.dependent_logical_tables.
- Returns:
- A list of LogicalTable
objects or dictionaries representing logical tables.
- Return type:
Union[list[LogicalTable], list[dict]]
- to_dict(camel_case=True)¶
Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.
- Parameters:
camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.
- Returns:
- A dictionary representation of object’s attributes and values.
By default, the dictionary keys are in camel case.
- Return type:
dict
- property columns¶
- mstrio.modeling.schema.table.warehouse_table.list_datasource_warehouse_tables(connection, datasource_id, namespace_id, name=None, refresh=False, to_dictionary=False, limit=None)¶
- Lists available warehouse tables in a specified datasource within a
specified namespace.
- Parameters:
connection (Connection) – Object representation of MSTR Connection.
datasource_id (str) – ID of a datasource.
namespace_id (str) – ID of a namespace within a given datasource_id.
name (str) – string by which to filter the table name
refresh (bool, optional) – Refresh warehouse table, default: False.
to_dictionary (bool, optional) – If True, the function will return list of dictionaries. Otherwise, list of WarehouseTable objects. Defaults to False.
limit (int, optional) – limit the number of elements returned. If None (default), all objects are returned.
- Returns:
- A list of WarehouseTable
or dictionary objects representing warehouse tables in a specified namespace in a specified datasource.
- Return type:
Union[list[”WarehouseTable”], list[dict]]
Examples
>>> datasource_id = "DAD6CAD6457DAF29E34463961688EA60" >>> namespace_id = "eyJucyI6InB1YmxpYyJ9" >>> available_wh_tables = list_datasource_warehouse_tables( connection, datasource_id, namespace_id)
- mstrio.modeling.schema.table.warehouse_table.list_warehouse_tables(connection, to_dictionary=False, name=None, datasource_id=None)¶
- Fetches all available warehouse table. This operation is done
asynchronously and is heavy: a lot of requests are performed to fetch all connected and available datasources, namespaces and finally warehouse tables for each combination. Additionally, the result could be filtered. Available filters are table name and datasource id. These filters can be combined.
- Parameters:
connection (Connection) – Object representation of MSTR Connection.
to_dictionary (bool, optional) – If True, returns a list of dictionaries. If False, returns a list of WarehouseTable objects.
name (str, optional) – A name of a warehouse table.
datasource_id (str, optional) – ID of a datasource.
- Returns:
- A list of dictionaries
or WarehouseTable objects.
- Return type:
list[WarehouseTable] | list[dict]