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

[GLUTEN-3705][FOLLOW][CH] Set the correct agg schema names after mapping one agg function to the other name #3734

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,19 @@ case class CHHashAggregateExecTransformer(
ConverterUtils.genColumnNameWithExprId(resultAttr)
} else {
val aggExpr = aggExpressions(columnIndex - groupingExprs.length)
val aggregateFunc = aggExpr.aggregateFunction
var aggFunctionName =
AggregateFunctionsBuilder.getSubstraitFunctionName(aggExpr.aggregateFunction).get
if (
ExpressionMappings.expressionExtensionTransformer.extensionExpressionsMapping.contains(
aggregateFunc.getClass)
) {
ExpressionMappings.expressionExtensionTransformer
.buildCustomAggregateFunction(aggregateFunc)
._1
.get
} else {
AggregateFunctionsBuilder.getSubstraitFunctionName(aggregateFunc).get
}
ConverterUtils.genColumnNameWithExprId(resultAttr) + "#Partial#" + aggFunctionName
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ case class CustomAggExpressionTransformer() extends ExpressionExtensionTrait {
aggregateFunc match {
case CustomSum(_, _) =>
mode match {
case Partial =>
// custom logic: can not support 'Partial'
/* case Partial =>
val aggBufferAttr = aggregateFunc.inputAggBufferAttributes
val attr = ConverterUtils.getAttrFromExpr(aggBufferAttr.head)
aggregateAttr += attr
reIndex += 1
reIndex
// custom logic: can not support 'Final'
/* case Final =>
reIndex */
case Final =>
aggregateAttr += aggregateAttributeList(reIndex)
reIndex += 1
reIndex */
reIndex
case other =>
throw new UnsupportedOperationException(s"Unsupported aggregate mode: $other.")
}
Expand All @@ -74,10 +74,12 @@ case class CustomAggExpressionTransformer() extends ExpressionExtensionTrait {
Some("custom_sum_double")
}
case _ =>
throw new UnsupportedOperationException(
s"Aggregate function ${aggregateFunc.getClass} is not supported.")
extensionExpressionsMapping.get(aggregateFunc.getClass)
}
if (substraitAggFuncName.isEmpty) {
throw new UnsupportedOperationException(
s"Aggregate function ${aggregateFunc.getClass} is not supported.")
}

(substraitAggFuncName, aggregateFunc.children.map(child => child.dataType))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/
package io.glutenproject.execution.extension

import io.glutenproject.execution.{CHHashAggregateExecTransformer, GlutenClickHouseTPCHAbstractSuite, HashAggregateExecBaseTransformer, WholeStageTransformerSuite}
import io.glutenproject.execution._
import io.glutenproject.substrait.SubstraitContext
import io.glutenproject.utils.SubstraitPlanPrinterUtil

import org.apache.spark.SparkConf
import org.apache.spark.sql.catalyst.FunctionIdentifier
Expand Down Expand Up @@ -81,18 +82,27 @@ class GlutenCustomAggExpressionSuite extends GlutenClickHouseTPCHAbstractSuite {
// Final stage is not supported, it will be fallback
WholeStageTransformerSuite.checkFallBack(df, false)

val aggExecs = df.queryExecution.executedPlan.collect {
val planExecs = df.queryExecution.executedPlan.collect {
case agg: HashAggregateExec => agg
case aggTransformer: HashAggregateExecBaseTransformer => aggTransformer
case wholeStage: WholeStageTransformer => wholeStage
}

assert(aggExecs(0).isInstanceOf[HashAggregateExec])
// First stage fallback
assert(planExecs(3).isInstanceOf[HashAggregateExec])

val substraitContext = new SubstraitContext
aggExecs(1).asInstanceOf[CHHashAggregateExecTransformer].doTransform(substraitContext)
planExecs(2).asInstanceOf[CHHashAggregateExecTransformer].doTransform(substraitContext)

// Check the functions
assert(substraitContext.registeredFunction.containsKey("custom_sum_double:req_fp64"))
assert(substraitContext.registeredFunction.containsKey("custom_sum:req_i64"))
assert(substraitContext.registeredFunction.containsKey("sum:req_fp64"))

val wx = planExecs(1).asInstanceOf[WholeStageTransformer].doWholeStageTransform()
val planJson = SubstraitPlanPrinterUtil.substraitPlanToJson(wx.root.toProtobuf)
assert(planJson.contains("#Partial#custom_sum_double"))
assert(planJson.contains("#Partial#custom_sum"))
assert(planJson.contains("#Partial#sum"))
}
}
Loading