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-6803]Init ExpressionUtil.extendedExpressionTransformer in executor side #6837

Closed
wants to merge 4 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ case class CHHashAggregateExecTransformer(
val aggregateFunc = aggExpr.aggregateFunction
var aggFunctionName =
if (
ExpressionMappings.expressionExtensionTransformer.extensionExpressionsMapping.contains(
ExpressionMappings.getExpressionExtensionTransformer.extensionExpressionsMapping.contains(
aggregateFunc.getClass)
) {
ExpressionMappings.expressionExtensionTransformer
ExpressionMappings.getExpressionExtensionTransformer
.buildCustomAggregateFunction(aggregateFunc)
._1
.get
Expand Down Expand Up @@ -437,10 +437,10 @@ case class CHHashAggregateExecPullOutHelper(
val aggregateFunc = exp.aggregateFunction
// First handle the custom aggregate functions
if (
ExpressionMappings.expressionExtensionTransformer.extensionExpressionsMapping.contains(
ExpressionMappings.getExpressionExtensionTransformer.extensionExpressionsMapping.contains(
aggregateFunc.getClass)
) {
ExpressionMappings.expressionExtensionTransformer
ExpressionMappings.getExpressionExtensionTransformer
.getAttrsIndexForExtensionAggregateExpr(
aggregateFunc,
exp.mode,
Expand Down
18 changes: 9 additions & 9 deletions gluten-core/src/main/scala/org/apache/gluten/GlutenPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,10 @@ private[gluten] class GlutenDriverPlugin extends DriverPlugin with Logging {
BackendsApiManager.initialize()
BackendsApiManager.getListenerApiInstance.onDriverStart(sc, pluginContext)
GlutenListenerFactory.addToSparkListenerBus(sc)

val expressionExtensionTransformer = ExpressionUtil.extendedExpressionTransformer(
conf.get(GlutenConfig.GLUTEN_EXTENDED_EXPRESSION_TRAN_CONF, "")
)

if (expressionExtensionTransformer != null) {
ExpressionMappings.expressionExtensionTransformer = expressionExtensionTransformer
}

ExpressionMappings.setExpressionExtensionTransformer(
ExpressionUtil.extendedExpressionTransformer(
conf.get(GlutenConfig.GLUTEN_EXTENDED_EXPRESSION_TRAN_CONF, "")
))
Collections.emptyMap()
}

Expand Down Expand Up @@ -277,6 +272,11 @@ private[gluten] class GlutenExecutorPlugin extends ExecutorPlugin {
// TODO categorize the APIs by driver's or executor's
BackendsApiManager.initialize()
BackendsApiManager.getListenerApiInstance.onExecutorStart(ctx)

ExpressionMappings.setExpressionExtensionTransformer(
ExpressionUtil.extendedExpressionTransformer(
conf.get(GlutenConfig.GLUTEN_EXTENDED_EXPRESSION_TRAN_CONF, "")
))
}

/** Clean up and terminate this plugin. For example: close the native engine. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ object AggregateFunctionsBuilder {
// First handle the custom aggregate functions
val (substraitAggFuncName, inputTypes) =
if (
ExpressionMappings.expressionExtensionTransformer.extensionExpressionsMapping.contains(
ExpressionMappings.getExpressionExtensionTransformer.extensionExpressionsMapping.contains(
aggregateFunc.getClass)
) {
val (substraitAggFuncName, inputTypes) =
ExpressionMappings.expressionExtensionTransformer.buildCustomAggregateFunction(
ExpressionMappings.getExpressionExtensionTransformer.buildCustomAggregateFunction(
aggregateFunc)
assert(substraitAggFuncName.isDefined)
(substraitAggFuncName.get, inputTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ object ExpressionConverter extends SQLConfHelper with Logging {

expr match {
case extendedExpr
if ExpressionMappings.expressionExtensionTransformer.extensionExpressionsMapping.contains(
extendedExpr.getClass) =>
if ExpressionMappings.getExpressionExtensionTransformer.extensionExpressionsMapping
.contains(extendedExpr.getClass) =>
// Use extended expression transformer to replace custom expression first
ExpressionMappings.expressionExtensionTransformer
ExpressionMappings.getExpressionExtensionTransformer
.replaceWithExtensionExpressionTransformer(substraitExprName, extendedExpr, attributeSeq)
case c: CreateArray =>
val children =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ package org.apache.gluten.expression

import org.apache.gluten.GlutenConfig
import org.apache.gluten.backendsapi.BackendsApiManager
import org.apache.gluten.exception.GlutenException
import org.apache.gluten.expression.ExpressionNames._
import org.apache.gluten.extension.{DefaultExpressionExtensionTransformer, ExpressionExtensionTrait}
import org.apache.gluten.extension.ExpressionExtensionTrait
import org.apache.gluten.sql.shims.SparkShimLoader

import org.apache.spark.sql.catalyst.expressions._
Expand Down Expand Up @@ -339,7 +340,7 @@ object ExpressionMappings {
def expressionsMap: Map[Class[_], String] = {
val blacklist = GlutenConfig.getConf.expressionBlacklist
val supportedExprs = defaultExpressionsMap ++
expressionExtensionTransformer.extensionExpressionsMapping
expressionExtensionTransformer.get.extensionExpressionsMapping
if (blacklist.isEmpty) {
supportedExprs
} else {
Expand All @@ -354,6 +355,20 @@ object ExpressionMappings {
.toMap[Class[_], String]
}

var expressionExtensionTransformer: ExpressionExtensionTrait =
DefaultExpressionExtensionTransformer()
private var expressionExtensionTransformer: Option[ExpressionExtensionTrait] = None

def getExpressionExtensionTransformer: ExpressionExtensionTrait = {
if (expressionExtensionTransformer.isEmpty) {
throw new GlutenException(
"The expressionExtensionTransformer is not set properly when ini driver or executor")
}
expressionExtensionTransformer.get
}

def setExpressionExtensionTransformer(value: ExpressionExtensionTrait): Unit = {
if (!expressionExtensionTransformer.isDefined) {
expressionExtensionTransformer = Some(value)
}
}

}
Loading