Module utils

Module utils 

Source

FunctionsΒ§

character_length_to_sql πŸ”’
date_part_to_sql πŸ”’
Converts a date_part function to SQL, tailoring it to the supported date field extraction style.
find_agg_expr πŸ”’
find_agg_node_within_select πŸ”’
Recursively searches children of LogicalPlan to find an Aggregate node if exists prior to encountering a Join, TableScan, or a nested subquery (derived table factor). If an Aggregate or node is not found prior to this or at all before reaching the end of the tree, None is returned.
find_unnest_node_until_relation πŸ”’
Recursively searches children of LogicalPlan to find Unnest node if exist until encountering a Relation node with single input
find_unnest_node_within_select πŸ”’
Recursively searches children of LogicalPlan to find Unnest node if exist
find_window_expr πŸ”’
find_window_nodes_within_select πŸ”’
Recursively searches children of LogicalPlan to find Window nodes if exist prior to encountering a Join, TableScan, or a nested subquery (derived table factor). If Window node is not found prior to this or at all before reaching the end of the tree, None is returned.
sqlite_date_trunc_to_sql πŸ”’
SQLite does not support timestamp/date scalars like to_timestamp, from_unixtime, date_trunc, etc. This uses the strftime function to format the timestamp as a string depending on the truncation unit.
sqlite_from_unixtime_to_sql πŸ”’
SQLite does not support timestamp/date scalars like to_timestamp, from_unixtime, date_trunc, etc. This remaps from_unixtime to datetime(expr, 'unixepoch'), expecting the input to be in seconds. It supports no other arguments, so if any are supplied it will return an error.
try_transform_to_simple_table_scan_with_filters πŸ”’
Iterates through the children of a LogicalPlan to find a TableScan node before encountering a Projection or any unexpected node that indicates the presence of a Projection (SELECT) in the plan. If a TableScan node is found, returns the TableScan node without filters, along with the collected filters separately. If the plan contains a Projection, returns None.
unproject_agg_exprs πŸ”’
Recursively identify all Column expressions and transform them into the appropriate aggregate expression contained in agg.
unproject_sort_expr πŸ”’
Transforms all Column expressions in a sort expression into the actual expression from aggregation or projection if found. This is required because if an ORDER BY expression is present in an Aggregate or Select, it is replaced with a Column expression (e.g., β€œsum(catalog_returns.cr_net_loss)”). We need to transform it back to the actual expression, such as sum(β€œcatalog_returns”.β€œcr_net_loss”).
unproject_unnest_expr πŸ”’
Recursively identify Column expressions and transform them into the appropriate unnest expression
unproject_window_exprs πŸ”’
Recursively identify all Column expressions and transform them into the appropriate window expression contained in window.