partitioned_agg_by
partitioned_agg_by
is a convenience method that performs an agg_by
operation on the source table and wraps the result in a PartitionedTable.
If the argument aggs
does not include a partition aggregation created by calling agg.partition()
, one will be added automatically with the default constituent column name __CONSTITUENT__
.
Syntax
partitioned_agg_by(
aggs: Sequence[Aggregation],
by: Sequence[str] = None,
preserve_empty: bool = False,
initial_groups: Table = None,
) -> PartitionedTable
Parameters
Parameter | Type | Description |
---|---|---|
aggs | Union[Aggregation, Sequence[Aggregagation]] | The aggregation(s) to apply to the source table. |
by optional | Union[str, Sequence[str]] | The group by column name(s). The default is |
preserve_empty optional | bool | Whether to keep result rows for groups that are initially empty, or become empty as a result of updates.
Each aggregation operator defines its own value for empty groups. The default is |
initial_groups optional | Table | A table whose distinct combinations of values for the group by column(s) should be used to create an initial set of aggregation groups. All other columns are ignored.
When a table is provided, the Note: Changes to this table are not expected or handled; if this table is a refreshing table, only its contents at instantiation time will be used. |
Returns
A PartitionedTable
.
Examples
In this example, partitioned_agg_by
returns the source
table, as partitioned by StreetName
.
The partitioned table is identical to the source table, so the constituent_tables
method is invoked to demonstrate that the table has been partitioned.
from deephaven import new_table
from deephaven.column import string_col, int_col, double_col
from deephaven import agg as agg
source = new_table(
[
string_col(
"HomeType",
[
"Colonial",
"Contemporary",
"Contemporary",
"Condo",
"Colonial",
"Apartment",
],
),
int_col("HouseNumber", [1, 3, 4, 15, 4, 9]),
string_col(
"StreetName",
[
"Test Drive",
"Community Circle",
"Test Drive",
"Deephaven Road",
"Community Circle",
"Deephaven Road",
],
),
int_col("SquareFeet", [2251, 1914, 4266, 1280, 3433, 981]),
int_col("Price", [450000, 400000, 1250000, 300000, 600000, 275000]),
]
)
result = source.partitioned_agg_by(
aggs=[agg.median(cols=["Size = SquareFeet"])], by=["StreetName"]
)
print(result.constituent_tables)
- source
- Log