You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "ulysses-you (via GitHub)" <gi...@apache.org> on 2023/10/07 07:25:25 UTC

Re: [PR] [WIP][EXTENSION] Inject Rule to fast fail gluten app if there are too much un-support operator [kyuubi]

ulysses-you commented on code in PR #5321:
URL: https://github.com/apache/kyuubi/pull/5321#discussion_r1349478817


##########
extensions/spark/kyuubi-extension-spark-3-3/src/main/scala/org/apache/kyuubi/sql/GlutenPlanManager.scala:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.sql
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.expressions.{ArrayContains, ArrayIntersect, ArraySort, Bin, Contains, EndsWith, LastDay, MakeDate, Overlay, Rand, Randn, Size, SortArray, StartsWith, ToUnixTimestamp, UnaryMinus, UnixTimestamp, UserDefinedExpression}
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.execution._
+import org.apache.spark.sql.execution.aggregate.{ObjectHashAggregateExec, SortAggregateExec}
+import org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat
+import org.apache.spark.sql.execution.exchange.ShuffleExchangeExec
+import org.apache.spark.sql.execution.joins.{BroadcastNestedLoopJoinExec, CartesianProductExec}
+
+/**
+ * [Experimental]Kyuubi extension for gluten enabled case.
+ * 1. check whether the plan contains too much unsupported operator
+ */
+case class GlutenPlanManager(session: SparkSession) extends ColumnarRule {
+  private val GLUTEN_DRIVER_PLUGIN_CLASS = "io.glutenproject.GlutenDriverPlugin"
+
+  override def preColumnarTransitions: Rule[SparkPlan] =
+    if (sys.props.get("spark.testing").nonEmpty ||
+      glutenEnabled(session.sparkContext.getConf)) {
+      GlutenPlanAnalysis
+    } else {
+      (plan: SparkPlan) => plan
+    }
+
+  private def glutenEnabled(conf: SparkConf): Boolean = {
+    conf.get("spark.plugins", "").contains(GLUTEN_DRIVER_PLUGIN_CLASS) &&
+    conf.get("spark.gluten.enabled", "true") == "true"
+  }
+}
+
+object GlutenPlanAnalysis extends Rule[SparkPlan] {
+
+  override def apply(plan: SparkPlan): SparkPlan = {
+    val count = plan.collect {
+      case p: FileSourceScanExec
+          if !p.relation.fileFormat.isInstanceOf[ParquetFileFormat] =>
+        true
+      case _: RowDataSourceScanExec |
+          _: CartesianProductExec |
+          _: ShuffleExchangeExec |
+          _: ObjectHashAggregateExec |
+          _: SortAggregateExec |
+          _: CoalesceExec |
+          _: GenerateExec |
+          _: RangeExec |
+          _: SampleExec |
+          _: BroadcastNestedLoopJoinExec =>
+        true
+      case p: SparkPlan
+          if p.expressions.exists(e =>
+            e.exists {
+              case _: UserDefinedExpression |
+                  _: UnaryMinus |
+                  _: Bin |
+                  _: Contains |
+                  _: StartsWith |
+                  _: EndsWith |

Review Comment:
   it seems `Contains`, `StartsWith`, `EndsWith ` are supported



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org