Skip to content

bug: can't handle aggregates within other value operations #507

Open
@gforsyth

Description

What happened?

We're handling certain aggregate functions incorrectly.

If the aggregate is within a separate ValueOp, like the below somecol.sum() / sumcol.sum() then we hit

TypeError: Parameter to MergeFrom() must be instance of same class: expected substrait.ibis.Expression got substrait.ibis.AggregateFunction.

because we're recursing down into the expression, but the AggregateRel needs to be handled outside of the current expression (i'm not exactly sure how at this point)

Here's a failing test case:

def test_value_op_aggregate(compiler):
    t = ibis.table([("a", "float"), ("b", "int32")], name="t")
    expr = t.aggregate(mkt_share=t.a.sum() / t.b.sum())

    result = translate(expr, compiler)

    assert result

What version of ibis-substrait are you using?

2.21.0

What substrait consumer(s) are you using, if any?

No response

Relevant log output

No response

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions