Summary
Aggregate textification incorrectly renders grouping expression references as field references when grouping expressions are non-trivial (e.g., function calls). This causes roundtrip failures.
Problem
The Substrait proto AggregateRel uses a level of indirection for groupings:
grouping_expressions: list of expressions (e.g., [abs($0)])
groupings[].expression_references: indices into grouping_expressions (e.g., [0])
The textifier builds arguments from expression_references as Value::Reference(i), which renders as $i. But $i in our text format means "field i of the input relation", not "grouping expression i". When grouping expressions are bare field refs like $0, the output is coincidentally correct. But for complex expressions like abs($0), the textifier produces $0 instead of abs($0).
Expected output:
Aggregate[abs($0) => abs($0), count($1)]
Actual output:
Aggregate[$0 => abs($0), count($1)]
Failing test
A failing roundtrip test is on branch wendell/aggregate-expr-grouping-bug (test_aggregate_expression_grouping_roundtrip in tests/plan_roundtrip.rs).
Relevant proto fields: AggregateRel.grouping_expressions and Grouping.expression_references.
Goal
The textifier should resolve expression_references indices through grouping_expressions to render the actual expressions in the arguments section, rather than emitting the raw index as a field reference.
Success Criteria
test_aggregate_expression_grouping_roundtrip passes
- Existing aggregate tests continue to pass
Summary
Aggregate textification incorrectly renders grouping expression references as field references when grouping expressions are non-trivial (e.g., function calls). This causes roundtrip failures.
Problem
The Substrait proto
AggregateReluses a level of indirection for groupings:grouping_expressions: list of expressions (e.g.,[abs($0)])groupings[].expression_references: indices intogrouping_expressions(e.g.,[0])The textifier builds arguments from
expression_referencesasValue::Reference(i), which renders as$i. But$iin our text format means "field i of the input relation", not "grouping expression i". When grouping expressions are bare field refs like$0, the output is coincidentally correct. But for complex expressions likeabs($0), the textifier produces$0instead ofabs($0).Expected output:
Actual output:
Failing test
A failing roundtrip test is on branch
wendell/aggregate-expr-grouping-bug(test_aggregate_expression_grouping_roundtripintests/plan_roundtrip.rs).Relevant proto fields:
AggregateRel.grouping_expressionsandGrouping.expression_references.Goal
The textifier should resolve
expression_referencesindices throughgrouping_expressionsto render the actual expressions in the arguments section, rather than emitting the raw index as a field reference.Success Criteria
test_aggregate_expression_grouping_roundtrippasses