def count(self, col: str): """ Count the number of values in the specified column on the table and return the result in a table with one row and one column. Args: col (str): the name of the column whose values to be counted Returns: a Table object Raises: DHError """ table_op = DedicatedAggOp(AggType.COUNT, count_column=col) return self.table_op_handler(table_op)
def max_by(self, by: List[str] = []): """ Perform max-by aggregation on the table and return the result table. Columns not used in the grouping must be of numeric types. Args: by (List[str], optional): the group-by column names, default is empty Returns: a Table object Raises: DHError """ table_op = DedicatedAggOp(AggType.MAX, column_names=by) return self.table_op_handler(table_op)
def last_by(self, by: List[str] = []): """ Perform last-by aggregation on the table and return the result table which contains the last row of each distinct group. Args: by (List[str], optional): the group-by column names, default is empty Returns: a Table object Raises: DHError """ table_op = DedicatedAggOp(AggType.LAST, column_names=by) return self.table_op_handler(table_op)
def count_by(self, col: str, by: List[str] = []): """ Perform count-by aggregation on the table and return the result table. The count of each group is stored in a new column named after the 'col' parameter. Args: col (str): the name of the column to store the counts by (List[str], optional): the group-by column names, default is empty Returns: a Table object Raises: DHError """ table_op = DedicatedAggOp(AggType.COUNT, column_names=by, count_column=col) return self.table_op_handler(table_op)
def std_by(self, column_names: List[str] = []): """ Perform std-by aggregation on the table and return the result table. Columns not used in the grouping must be of numeric types. Args: column_names (List[str]): the group-by column names Returns: a Table object Raises: DHError """ table_op = DedicatedAggOp(AggType.STD, column_names=column_names) return self.table_op_handler(table_op)
def group_by(self, by: List[str] = []): """ Perform a group-by aggregation on the table and return the result table. After the operation, the columns not in the group-by columns become array-type. If no group-by column is given,the content of each column is grouped into its own array. Args: by (List[str], optional): the group-by column names; default is empty Returns: a Table object Raises: DHError """ table_op = DedicatedAggOp(AggType.GROUP, column_names=by) return self.table_op_handler(table_op)