Skip to content

Commit

Permalink
[GLUTEN-7143][VL] RAS: Catch exceptions thrown from rewrite rules (#7767
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zhztheplayer authored Nov 1, 2024
1 parent efeef65 commit 527ab16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.apache.gluten.ras.path.Pattern.node
import org.apache.gluten.ras.rule.{RasRule, Shape}
import org.apache.gluten.ras.rule.Shapes.pattern

import org.apache.spark.internal.Logging
import org.apache.spark.sql.execution.SparkPlan

import scala.reflect.{classTag, ClassTag}
Expand Down Expand Up @@ -70,7 +71,9 @@ object RasOffload {
new RuleImpl(base, validator)
}

private class RuleImpl(base: RasOffload, validator: Validator) extends RasRule[SparkPlan] {
private class RuleImpl(base: RasOffload, validator: Validator)
extends RasRule[SparkPlan]
with Logging {
private val typeIdentifier: TypeIdentifier = base.typeIdentifier()

final override def shift(node: SparkPlan): Iterable[SparkPlan] = {
Expand All @@ -86,14 +89,25 @@ object RasOffload {
}

// 2. Rewrite the node to form that native library supports.
val rewritten = rewrites.foldLeft(node) {
case (node, rewrite) =>
node.transformUp {
case p =>
val out = rewrite.rewrite(p)
out
val rewritten =
try {
rewrites.foldLeft(node) {
case (node, rewrite) =>
node.transformUp {
case p =>
val out = rewrite.rewrite(p)
out
}
}
}
} catch {
case e: Exception =>
// TODO: Remove this catch block
// See https://github.com/apache/incubator-gluten/issues/7766
logWarning(
s"Exception thrown during rewriting the plan ${node.nodeName}. Skip offloading it",
e)
return List.empty
}

// 3. Walk the rewritten tree.
val offloaded = rewritten.transformUp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ class RewriteSparkPlanRulesManager private (rewriteRules: Seq[RewriteSingleNode]
}
(rewrittenPlan, None)
} catch {
case e: Exception => (origin, Option(e.getMessage))
case e: Exception =>
// TODO: Remove this catch block
// See https://github.com/apache/incubator-gluten/issues/7766
(origin, Option(e.getMessage))
}
}

Expand Down

0 comments on commit 527ab16

Please sign in to comment.