Skip to content

Commit

Permalink
fix NPE issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JkSelf committed Aug 13, 2024
1 parent 1e5a7c9 commit 0fa27b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,19 @@ object AggregateFunctionsBuilder {
val functionMap = args.asInstanceOf[java.util.HashMap[String, java.lang.Long]]

// First handle the custom aggregate functions
val (substraitAggFuncName, inputTypes) =
if (
ExpressionMappings.expressionExtensionTransformer.extensionExpressionsMapping.contains(
aggregateFunc.getClass)
) {
val (substraitAggFuncName, inputTypes) =
ExpressionMappings.expressionExtensionTransformer.buildCustomAggregateFunction(
aggregateFunc)
assert(substraitAggFuncName.isDefined)
(substraitAggFuncName.get, inputTypes)
} else {
val substraitAggFuncName = getSubstraitFunctionName(aggregateFunc)

// Check whether each backend supports this aggregate function.
if (
!BackendsApiManager.getValidatorApiInstance.doExprValidate(
substraitAggFuncName,
aggregateFunc)
) {
throw new GlutenNotSupportException(
s"Aggregate function not supported for $aggregateFunc.")
}
val substraitAggFuncName = getSubstraitFunctionName(aggregateFunc)

// Check whether each backend supports this aggregate function.
if (
!BackendsApiManager.getValidatorApiInstance.doExprValidate(
substraitAggFuncName,
aggregateFunc)
) {
throw new GlutenNotSupportException(s"Aggregate function not supported for $aggregateFunc.")
}

val inputTypes: Seq[DataType] = aggregateFunc.children.map(child => child.dataType)
(substraitAggFuncName, inputTypes)
}
val inputTypes: Seq[DataType] = aggregateFunc.children.map(child => child.dataType)

ExpressionBuilder.newScalarFunction(
functionMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ object ExpressionConverter extends SQLConfHelper with Logging {

expr match {
case extendedExpr
if ExpressionMappings.expressionExtensionTransformer.extensionExpressionsMapping.contains(
extendedExpr.getClass) =>
if ExpressionMappings.expressionExtensionTransformer != null
&& ExpressionMappings.expressionExtensionTransformer.extensionExpressionsMapping
.contains(extendedExpr.getClass) =>
// Use extended expression transformer to replace custom expression first
ExpressionMappings.expressionExtensionTransformer
.replaceWithExtensionExpressionTransformer(substraitExprName, extendedExpr, attributeSeq)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,11 @@ object ExpressionMappings {

def expressionsMap: Map[Class[_], String] = {
val blacklist = GlutenConfig.getConf.expressionBlacklist
val supportedExprs = defaultExpressionsMap ++
expressionExtensionTransformer.extensionExpressionsMapping

var supportedExprs = defaultExpressionsMap
if (expressionExtensionTransformer != null) {
supportedExprs = supportedExprs ++ expressionExtensionTransformer.extensionExpressionsMapping
}
if (blacklist.isEmpty) {
supportedExprs
} else {
Expand Down

0 comments on commit 0fa27b2

Please sign in to comment.