Skip to content

Commit

Permalink
[VL] Clean up some legacy code for expression validation (#4508)
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE authored Jan 25, 2024
1 parent 7df896b commit 5ca4ed2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import org.apache.spark.sql.types._

class ValidatorApiImpl extends ValidatorApi {

/** For velox backend, key validation is on native side. */
override def doExprValidate(substraitExprName: String, expr: Expression): Boolean =
doExprValidate(Map(), substraitExprName, expr)
true

override def doNativeValidateWithFailureReason(plan: PlanNode): NativePlanValidationInfo = {
val tmpRuntime = Runtimes.tmpInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,21 @@
*/
package io.glutenproject.backendsapi

import io.glutenproject.expression.{ExpressionMappings, ExpressionNames}
import io.glutenproject.extension.ValidationResult
import io.glutenproject.substrait.plan.PlanNode
import io.glutenproject.validate.NativePlanValidationInfo

import org.apache.spark.sql.catalyst.expressions.{Alias, Expression, Generator}
import org.apache.spark.sql.catalyst.expressions.{Expression, Generator}
import org.apache.spark.sql.catalyst.plans.physical.Partitioning
import org.apache.spark.sql.execution.SparkPlan
import org.apache.spark.sql.types.DataType

object TypeKey {
final val EMPTY_TYPE = ""
final val ARRAY_TYPE = "array"
final val MAP_TYPE = "map"
final val STRUCT_TYPE = "struct"
}

/**
* Determine if a plan or expression can be accepted by the backend, or we fallback the execution to
* vanilla Spark.
*/
trait ValidatorApi {

/**
* Validate target expression within an input blacklist. Return false if target expression (with
* the information of its args' types) matches any of the entry in the blacklist.
*/
protected def doExprValidate(
blacklist: Map[String, Set[String]],
substraitExprName: String,
expr: Expression): Boolean = {
// To handle cast(struct as string) AS col_name expression
val key = if (substraitExprName.toLowerCase().equals(ExpressionNames.ALIAS)) {
ExpressionMappings.expressionsMap.get(expr.asInstanceOf[Alias].child.getClass)
} else Some(substraitExprName)
if (key.isEmpty) return false
if (blacklist.isEmpty) return true
val value = blacklist.get(key.get)
if (value.isEmpty) {
return true
}
val inputTypeNames = value.get
inputTypeNames.foreach {
inputTypeName =>
if (inputTypeName.equals(TypeKey.EMPTY_TYPE)) {
return false
} else {
for (input <- expr.children) {
if (inputTypeName.equals(input.dataType.typeName)) {
return false
}
}
}
}
true
}

/**
* Validate expression for specific backend, including input type. If the expression isn't
* implemented by the backend or it returns mismatched results with Vanilla Spark, it will fall
Expand Down

0 comments on commit 5ca4ed2

Please sign in to comment.