pydeephaven.query#
- class Query(session, table)[source]#
Bases:
TableInterface
A Query object is used to define and execute a sequence of Deephaven table operations on the server.
When the query is executed, the table operations specified for the Query object are batched together and sent to the server in a single request, thus avoiding multiple round trips between the client and the server. The result of executing the query is a new Deephaven table.
Note, an application should always use the factory method on the Session object to create a Query instance as the constructor is subject to future changes to support more advanced features already planned.
- agg_by(agg, by)[source]#
Add a Combined Aggregation operation to the query.
- Parameters:
by (List[str]) – the group-by column names
agg (ComboAggregation) – the combined aggregation definition
- Returns:
self
- aj(table, on, joins=[], match_rule=MatchRule.LESS_THAN_EQUAL)[source]#
Add a as-of join operation to the query.
- Parameters:
table (Table) – the right-table of the join
on (List[str]) – the columns to match, can be a common name or an equal expression, i.e. “col_a = col_b” for different column names
joins (List[str], optional) – a list of the columns to be added from the right table to the result table, can be renaming expressions, i.e. “new_col = col”; default is empty
match_rule (MatchRule, optional) – the match rule for the as-of join, default is LESS_THAN_EQUAL
- Returns:
self
- avg_by(by=[])[source]#
Add an avg-by aggregation to the query.
- Parameters:
by (List[str], optional) – the group-by column names, default is empty
- Returns:
self
- count(col)[source]#
Add a count operation to the query.
- Parameters:
col (str) – the name of the column whose values to be counted
- Returns:
self
- count_by(col, by=[])[source]#
Add a count-by aggregation to the query.
- Parameters:
col (str) – the name of the column to store the counts
by (List[str], optional) – the group-by column names, default is empty
- Returns:
self
- drop_columns(cols)[source]#
Add a drop-columns operation to the query.
- Parameters:
cols (List[str]) – the list of column names
- Returns:
self
- exact_join(table, on, joins=[])[source]#
Add an exact-join operation to the query.
- Parameters:
table (Table) – the right-table of the join
on (List[str]) – the columns to match, can be a common name or an equal expression, i.e. “col_a = col_b” for different column names
joins (List[str], optional) – a list of the columns to be added from the right table to the result table, can be renaming expressions, i.e. “new_col = col”; default is empty
- Returns:
self
- exec()[source]#
Execute the query on the server and return the result table.
- Returns:
a Table object
- Raises:
DHError –
- first_by(by=[])[source]#
Add a first-by aggregation to the query.
- Parameters:
by (List[str], optional) – the group-by column names, default is empty
- Returns:
self
- group_by(by=[])[source]#
Add a group-by aggregation to the query.
- Parameters:
by (List[str], optional) – the group-by column names; default is empty
- Returns:
self
- head(num_rows)[source]#
Add a head operation to the query.
- Parameters:
num_rows (int) – the number of rows at the head of table
- Returns:
self
- head_by(num_rows, by)[source]#
Add a head-by operation to the query.
- Parameters:
num_rows (int) – the number of rows at the beginning of each group
by (List[str]) – the group-by column names
- Returns:
self
- join(table, on=[], joins=[], reserve_bits=10)[source]#
Add a cross-join operation to the query.
- Parameters:
table (Table) – the right-table of the join
on (List[str]) – the columns to match, can be a common name or an equal expression, i.e. “col_a = col_b” for different column names
joins (List[str], optional) – a list of the columns to be added from the right table to the result table, can be renaming expressions, i.e. “new_col = col”; default is empty
reserve_bits (int, optional) – the number of bits of key-space to initially reserve per group; default is 10
- Returns:
self
- last_by(by=[])[source]#
Add a last-by aggregation to the query.
- Parameters:
by (List[str], optional) – the group-by column names, default is empty
- Returns:
self
- lazy_update(formulas)[source]#
Add an lazy-update operation to the query.
- Parameters:
formulas (List[str]) – the column formulas
- Returns:
self
- max_by(by=[])[source]#
Add a max-by aggregation to the query.
- Parameters:
by (List[str], optional) – the group-by column names, default is empty
- Returns:
self
- median_by(by=[])[source]#
Add a median-by aggregation to the query.
- Parameters:
by (List[str], optional) – the group-by column names, default is empty
- Returns:
self
- min_by(by=[])[source]#
Add a min-by aggregation to the query.
- Parameters:
by (List[str], optional) – the group-by column names, default is empty
- Returns:
self
- natural_join(table, on, joins=[])[source]#
Add a natural-join operation to the query.
- Parameters:
table (Table) – the right-table of the join
on (List[str]) – the columns to match, can be a common name or an equal expression, i.e. “col_a = col_b” for different column names
joins (List[str], optional) – a list of the columns to be added from the right table to the result table, can be renaming expressions, i.e. “new_col = col”; default is empty
- Returns:
self
- raj(table, on, joins=[], match_rule=MatchRule.GREATER_THAN_EQUAL)[source]#
Add a reverse as-of join operation to the query.
- Parameters:
table (Table) – the right-table of the join
on (List[str]) – the columns to match, can be a common name or an equal expression, i.e. “col_a = col_b” for different column names
joins (List[str], optional) – a list of the columns to be added from the right table to the result table, can be renaming expressions, i.e. “new_col = col”; default is empty
match_rule (MatchRule, optional) – the match rule for the as-of join, default is GREATER_THAN_EQUAL
- Returns:
self
- select(formulas=[])[source]#
Add a select operation to the query.
- Parameters:
formulas (List[str], optional) – the column formulas, default is empty
- Returns:
self
- select_distinct(cols=[])[source]#
Add a select-distinct operation to the query.
- Parameters:
cols (List[str], optional) – the list of column names, default is empty
- Returns:
self
- snapshot_when(trigger_table, stamp_cols=None, initial=False, incremental=False, history=False)[source]#
Add a snapshot_when operation to the query.
- Returns:
self
- sort(order_by, order=[])[source]#
Add sort operation to the query.
- Parameters:
order_by (List[str]) – the names of the columns to be sorted on
order (List[SortDirection], optional) – the corresponding sort directions for each sort column, default is empty. In the absence of explicit sort directions, data will be sorted in the ascending order.
- Returns:
self
- std_by(by=[])[source]#
Add a std-by aggregation to the query.
- Parameters:
by (List[str]) – the group-by column names
- Returns:
self
- sum_by(by=[])[source]#
Add a sum-by aggregation to the query.
- Parameters:
by (List[str]) – the group-by column names
- Returns:
self
- tail(num_rows)[source]#
Add a tail operation to the query.
- Parameters:
num_rows (int) – the number of rows at the end of table
- Returns:
self
- tail_by(num_rows, by)[source]#
Add a tail-by operation to the query.
- Parameters:
num_rows (int) – the number of rows at the end of each group
by (List[str]) – the group-by column names
- Returns:
self
- ungroup(cols=[], null_fill=True)[source]#
Add an ungroup operation to the query.
- Parameters:
cols (List[str], optional) – the names of the array columns, if empty, all array columns will be ungrouped, default is empty
null_fill (bool, optional) – indicates whether null should be used to fill missing cells, default is True
- Returns:
self
- update(formulas)[source]#
Add an update operation to the query.
- Parameters:
formulas (List[str]) – the column formulas
- Returns:
self
- update_by(ops, by)[source]#
Add an update-by operation to the query.
- Parameters:
ops (List[UpdateByOperation]) – the UpdateByOperations to be applied
by (List[str]) – the group-by column names
- Returns:
self
- update_view(formulas)[source]#
Add an update-view operation to the query.
- Parameters:
formulas (List[str]) – the column formulas
- Returns:
self
- var_by(by=[])[source]#
Add a var-by aggregation to the query.
- Parameters:
by (List[str], optional) – the group-by column names, default is empty
- Returns:
self