Github user JoshRosen commented on the pull request:
https://github.com/apache/spark/pull/9038#issuecomment-147125927
Okay, I have a theory as to what might be causing the test failure. The
assertion failure is only occurring in the final aggregation,
`finalAndCompleteAggregate`.
Consider the input of `finalAndCompleteAggregate`: this is the output of
`partialMergeAggregate`, whose result expressions are
```scala
groupingAttributes ++
Seq(distinctColumnAttribute) ++
partialMergeAggregateExpressions.flatMap(_.aggregateFunction.inputAggBufferAttributes)
```
Here, the input to the `finalAndCompleteAggregate` is a partial aggregate
because its attributes are `inputAggBufferAttributes`. If we fall back to sort
while evaluating `finalAndCompleteAggregate` then we need to extract the
partial aggregate results from the input row rather than calling `processRow`
to initialize empty aggregation buffers. I think that this is the first
problem: it looks like we're mistakenly calling the `needsProcess` branch
instead. In this branch, the `inputBufferOffset`s of the imperative aggregate
functions will not have been set properly, which I think is leading to wrong
answers.
I tried redefining `needsProcess` as
```scala
val needsProcess = (initialInputBufferOffset == 0)
```
but this led to attribute binding errors. Therefore, I think that we might
be assigning the wrong attributes to the result of `partialMergeAggregate`. I'm
going to try to fix this by changing the attributes of `partialMergeAggregate`
and refactoring the logic when falling back to sort.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]