flowmachine.core.sqlalchemy_utils¶
get_query_result_as_dataframe¶
get_query_result_as_dataframe(query, *, engine)
Run the given sqlalchemy query and return the result as a pandas DataFrame.
Parameters¶
-
query
:sqlalchemy.sql.Selectable
The SQLAlchemy query to run.
-
engine
:sqlalchemy.engine.Engine
SQLAlchemy engine to use for reading the table information.
Returns¶
-
pandas.DataFrame
Data frame containing the result.
get_sql_string¶
get_sql_string(sqlalchemy_query)
Return SQL string compiled from the given sqlalchemy query (using the PostgreSQL dialect).
Parameters¶
-
sqlalchemy_query
:sqlalchemy.sql.Selectable
SQLAlchemy query
Returns¶
-
str
SQL string compiled from the sqlalchemy query.
get_sqlalchemy_table_definition¶
get_sqlalchemy_table_definition(fully_qualified_table_name, *, engine)
Return sqlalchemy Table object for table with the given name.
Parameters¶
-
fully_qualified_table_name
:str
Fully qualified table name, for example: "events.calls"
-
engine
:sqlalchemy.engine.Engine
SQLAlchemy engine to use for reading the table information.
Returns¶
sqlalchemy.Table
get_string_representation¶
get_string_representation(sqlalchemy_expr, engine=None)
Return a string containing a SQL fragment which is compiled from the given sqlalchemy expression.
Returns¶
-
str
String representation of the sqlalchemy expression.
make_sqlalchemy_column_from_flowmachine_column_description¶
make_sqlalchemy_column_from_flowmachine_column_description(
sqlalchemy_table, column_str
)
Given a sqlalchemy sqlalchemy_table and a string with a column description, return the actual sqlalchemy Column object (or a sqlalchemy Label object if column_str
contains an alias such as "
Parameters¶
-
table
:sqlalchemy.Table
The sqlalchemy_table for which to obtain the column.
-
column_str
:str
The column name, optionally describing an alias via
Returns¶
sqlalchemy.sql.elements.Label
,sqlalchemy.Column
Examples¶
>>> make_sqlalchemy_column_from_flowmachine_column_description(sqlalchemy_table, "msisdn") >>> make_sqlalchemy_column_from_flowmachine_column_description(sqlalchemy_table, "msisdn AS subscriber")