@@ -266,11 +266,28 @@ def compute_values(self, assignments: Sequence[ex.Expression]):
266266 )
267267
268268 def compute_general_expression (self , assignments : Sequence [ex .Expression ]):
269+ """
270+ Applies arbitrary column expressions to the current execution block.
271+
272+ This method transforms the logical plan by applying a sequence of expressions that
273+ preserve the length of the input columns. It supports both scalar operations
274+ and window functions. Each expression is assigned a unique internal column identifier.
275+
276+ Args:
277+ assignments (Sequence[ex.Expression]): A sequence of expression objects
278+ representing the transformations to apply to the columns.
279+
280+ Returns:
281+ Tuple[ArrayValue, Tuple[str, ...]]: A tuple containing:
282+ - An `ArrayValue` wrapping the new root node of the updated logical plan.
283+ - A tuple of strings representing the unique column IDs generated for
284+ each expression in the assignments.
285+ """
269286 named_exprs = [
270287 nodes .ColumnDef (expr , ids .ColumnId .unique ()) for expr in assignments
271288 ]
272289 # TODO: Push this to rewrite later to go from block expression to planning form
273- new_root = expression_factoring .plan_general_col_exprs (self .node , named_exprs )
290+ new_root = expression_factoring .apply_col_exprs_to_plan (self .node , named_exprs )
274291
275292 target_ids = tuple (named_expr .id for named_expr in named_exprs )
276293 return (ArrayValue (new_root ), target_ids )
@@ -282,7 +299,29 @@ def compute_general_reduction(
282299 * ,
283300 dropna : bool = False ,
284301 ):
285- # Warning: this function does not check if the expression is a valid reduction, and may fail spectacularly on invalid inputs
302+ """
303+ Applies arbitrary aggregation expressions to the block, optionally grouped by keys.
304+
305+ This method handles reduction operations (e.g., sum, mean, count) that collapse
306+ multiple input rows into a single scalar value per group. If grouping keys are
307+ provided, the operation is performed per group; otherwise, it is a global reduction.
308+
309+ Args:
310+ assignments (Sequence[ex.Expression]): A sequence of aggregation expressions
311+ to be calculated.
312+ by_column_ids (typing.Sequence[str], optional): A sequence of column IDs
313+ to use as grouping keys. Defaults to an empty tuple (global reduction).
314+ dropna (bool, optional): If True, rows containing null values in the
315+ `by_column_ids` columns will be filtered out before the reduction
316+ is applied. Defaults to False.
317+
318+ Returns:
319+ Tuple[ArrayValue, Tuple[str, ...]]: A tuple containing:
320+ - An `ArrayValue` wrapping the new root node representing the
321+ aggregation/group-by result.
322+ - A tuple of strings representing the unique column IDs assigned to the
323+ resulting aggregate columns.
324+ """
286325 plan = self .node
287326 if dropna :
288327 for col_id in by_column_ids :
@@ -292,7 +331,7 @@ def compute_general_reduction(
292331 nodes .ColumnDef (expr , ids .ColumnId .unique ()) for expr in assignments
293332 ]
294333 # TODO: Push this to rewrite later to go from block expression to planning form
295- new_root = expression_factoring .plan_general_aggregation (
334+ new_root = expression_factoring .apply_agg_exprs_to_plan (
296335 plan , named_exprs , grouping_keys = [ex .deref (by ) for by in by_column_ids ]
297336 )
298337 target_ids = tuple (named_expr .id for named_expr in named_exprs )
0 commit comments