Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: workaround for aggregates in datafusion #1120

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion ibis_substrait/compiler/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,39 @@ def aggregate(
],
)

return stalg.Rel(aggregate=aggregate)
rel = stalg.Rel(aggregate=aggregate)

# TODO: ProjectRel below is injected as a temporary workaround because datafusion seems to require projection after an aggregation

len_aggregate_output = len(op.groups.values()) + len(op.metrics.values())

mapping_counter = itertools.count(len_aggregate_output)

return stalg.Rel(
project=stalg.ProjectRel(
common=stalg.RelCommon(
emit=stalg.RelCommon.Emit(
output_mapping=[
next(mapping_counter) for _ in range(len_aggregate_output)
]
)
),
input=rel,
expressions=[
stalg.Expression(
selection=stalg.Expression.FieldReference(
root_reference=stalg.Expression.FieldReference.RootReference(),
direct_reference=stalg.Expression.ReferenceSegment(
struct_field=stalg.Expression.ReferenceSegment.StructField(
field=i,
),
),
)
)
for i in range(len_aggregate_output)
],
)
)


@translate.register(ops.SimpleCase)
Expand Down
Loading