Skip to content

Conversation

@Zouxxyy
Copy link
Contributor

@Zouxxyy Zouxxyy commented Jan 5, 2026

What changes are proposed in this pull request?

rewriteAggBufferAttributes is only needed by PartialMerge and Final mode

How was this patch tested?

test by the existing cases

@github-actions github-actions bot added the VELOX label Jan 5, 2026
@Zouxxyy Zouxxyy changed the title [VL] Skip rewriteAggBufferAttributes to Complete agg mode [VL] Do not rewriteAggBufferAttributes for Complete agg mode Jan 5, 2026
@jinchengchenghh jinchengchenghh requested a review from rui-mo January 6, 2026 06:13
Copy link
Contributor

@rui-mo rui-mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify if this change fixes an existing problem? Thanks.

@Zouxxyy
Copy link
Contributor Author

Zouxxyy commented Jan 12, 2026

@rui-mo During our implementation of hybrid AGG (where a single AGG contains both partial-merge and complete modes), we discovered this issue:
Inside rewriteAggBufferAttributes, the code compares aggBufferAttrs with InputAttributes, which is actually incorrect in Complete mode. However, since Spark + Gluten currently does not support having both partial-merge and complete functions simultaneously, the current code path will not trigger this scenario, and it's difficult to construct a unit test (UT) for it. Nevertheless, I think we can add this defensive code.

// Add a projection node before aggregation for row constructing.
// Mainly used for aggregation whose intermediate type is a compound type in Velox.
// Pre-projection is never required for final stages.
private def applyRowConstruct(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be called for the Complete mode, as rowConstructNeeded() returns false for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be called for the Complete mode, as rowConstructNeeded() returns false for it?

As mentioned earlier, we implemented a hybrid AGG that contains both PartialMerge (or Final) and complete aggregation functions, and rowConstructNeeded is triggered as long as a PartialMerge (or Final) function is present.

It won't be triggered for the now code, but I think we can add defensive code to handle this scenario in future implementations .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rowConstructNeeded is triggered as long as a PartialMerge (or Final) function is present

Are you referring to the modified code on your side, or the current Gluten code?

As mentioned earlier, we implemented a hybrid AGG that contains both PartialMerge (or Final) and complete aggregation functions

Is there any plan to upstream this change to Gluten, or will it remain local to your side?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to the modified code on your side, or the current Gluten code?

The current Gluten code, see this

  private def rowConstructNeeded(): Boolean = aggregateExpressions.exists {
    case AggregateExpression(aggFunc, PartialMerge | Final, _, _, _) =>
      aggFunc.inputAggBufferAttributes.size > 1
    case _ => false
  }

Is there any plan to upstream this change to Gluten, or will it remain local to your side?

Oh, maybe it can be launched when it becomes stable!

val functionInputAttributes = aggFunc.inputAggBufferAttributes
aggFunc match {
case _ if aggregateExpression.mode == Partial =>
case _ if aggregateExpression.mode == Partial || aggregateExpression.mode == Complete =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that mixing Complete mode with other modes isn’t supported, but is there a way to add a unit test for pure Complete mode to ensure this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have pure complete mode case, see #7752, and it can run correctly

Copy link
Contributor

@jackylee-ch jackylee-ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It also works in our environments.

@rui-mo rui-mo merged commit b0e514f into apache:main Jan 14, 2026
108 of 109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants