Skip to content

Aggregate textification renders expression indices as field references #76

@wackywendell

Description

@wackywendell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions