ExaExtension#
- class pyexasol.ExaExtension(connection)[source]#
Bases:
objectThis class extends the functionality of a simple SQL driver to address common Exasol-related problems.
Tip
You may access these functions using .ext property of connection object.
Examples
>>> C = pyexasol.connect(...) ... print(C.ext.get_disk_space_usage())
- explain_last(details: bool = False)[source]#
- Parameters:
details (bool) –
False, the function returns the average (AVG) or maximum (MAX) values aggregated for all Exasol nodes.True, the function returns separate rows for each individual Exasol node, with a column labeled “iproc” representing the node.
- Returns:
Profiling information for last executed query.
Note
This function should be called immediately after
execute()COMMIT,ROLLBACKandFLUSH STATISTICSqueries are ignored.Tip
Details are useful to detect bad data distribution and imbalanced execution If you want to see real values of
CPU, MEM, HDD, NETcolumns, please enable Exasol profiling first with:ALTER SESSION SET PROFILE = 'ON';Please refer to Exasol User Manuals for explanations about profiling columns.
- export_to_pandas_with_dtype(query_or_table, query_params=None)[source]#
Export to pandas and attempt to guess correct dtypes based on Exasol columns.
- Parameters:
query_or_table –
Source from which to export data. Can be one of:
tuple[str, ...]: schema-qualified table identifier, such as("SCHEMA", "TABLE").str: if it contains a non-trailing space, it is treated like an SQL query. Otherwise, it is treated like a table identifier.
query_params – Additional query parameters.
Note
Since pandas has significantly smaller range of allowed values, this function makes many assumptions. Please use it as baseline for your own function for complex cases.
Exasol Type
Pandas Type
Small decimal
int32
Big decimal
int64
Double
float64
Date, Timestamp
datetime64[ns]
Everything else
category (!)
- get_columns(object_name)[source]#
Get information about columns of table or view.
- Parameters:
object_name – Object name may be passed as tuple to specify custom schema.
Caution
DEPRECATED, please use
.meta.sql_columnsinstead.
- get_columns_sql(query, query_params=None)[source]#
Get columns of SQL query without executing it.
- Parameters:
query – SQL query string to get columns for.
query_params – Optional query parameters.
Caution
DEPRECATED, please use
.meta.sql_columnsinstead.Note
It relies on a prepared statement that will be closed immediately without execution
- get_disk_space_usage()[source]#
Get the disk space usage of the Exasol DB.
- Returns:
A dict with 4 keys, providing all disk space details.
Key
Description
occupied_sizeHow much space is occupied (in bytes)
free_sizeHow much space is available (in bytes)
total_sizeoccupied_size + free_size
occupied_size_percentPercentage of occupied disk space (0-100%)
Note
Exasol still lacks a standard function to measure actual disk space usage. We are trying to mitigate this problem by creating a custom function.
- get_reserved_words()[source]#
Get reserved keywords which cannot be used as identifiers without double-quotes.
Caution
DEPRECATED, please use
.meta.list_sql_keywordsinstead.Warning
Never hard-code this list! It changes with every Exasol versions.
- get_sys_columns(object_name)[source]#
Get information about columns of table or view (SYS format)
- Parameters:
object_name – Object name may be passed as tuple to specify custom schema.
Caution
DEPRECATED, please use
.meta.list_columnsinstead.
- get_sys_schemas(schema_name_prefix: str = '')[source]#
Get information about schemas (SYS format)
- Parameters:
schema_name_prefix – Output may be optionally filtered by schema name prefix
Caution
DEPRECATED, please use
.meta.list_schemasinstead.
- get_sys_tables(schema=None, table_name_prefix='')[source]#
Get information about tables in selected schema(SYS format)
- Parameters:
schema
table_name_prefix – Output may be optionally filtered by table name prefix.
Caution
DEPRECATED, please use
.meta.list_tablesinstead.
- get_sys_views(schema: str | None = None, view_name_prefix: str = '')[source]#
Get information about views in selected schema (SYS format)
- Parameters:
schema
view_name_prefix – Output may be optionally filtered by view name prefix.
Caution
DEPRECATED, please use
.meta.list_viewsinstead.
- insert_multi(table_name, data, columns=None)[source]#
Insert a small number of rows into a table using a prepared statement.
- Parameters:
table_name – Target table for INSERT.
data – Source object implementing
__iter__(e.g. list or tuple).columns – List of column names to specify custom order of columns.
Tip
Compared to
.import_from_iterable, this method offers better performance for small data sets of 10,000 rows or fewer.Use
.import_from_iterablefor larger data sets and better memory efficiencyUse
.import_from_pandasto import frompandas.DataFrameregardless of its sizeUse
.import_from_parquetto import from parquet filesUse
.import_from_polarsto import frompolars.DataFrameregardless of its size
You may use “columns” argument to specify custom order of columns for insertion If some columns are not included in this list,
NULLorDEFAULTvalue will be used insteadNote
Please note that data should be presented in a row format. You may use
zip(*data_cols)to convert columnar format into row format.