Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/6356#discussion_r30962409
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala ---
@@ -1321,3 +1201,137 @@ object SQLContext {
}
}
}
+
+
+
+/**
+ * :: DeveloperApi ::
+ * The primary workflow for executing relational queries using Spark.
Designed to allow easy
+ * access to the intermediate phases of query execution for developers.
+ */
+@DeveloperApi
+class QueryExecution(val sqlContext: SQLContext, val logical: LogicalPlan)
{
+ val analyzer = sqlContext.analyzer
+ val optimizer = sqlContext.optimizer
+ val planner = sqlContext.planner
+ val cacheManager = sqlContext.cacheManager
+ val prepareForExecution = sqlContext.prepareForExecution
+
+ def assertAnalyzed(): Unit = analyzer.checkAnalysis(analyzed)
+
+ lazy val analyzed: LogicalPlan = analyzer.execute(logical)
+ lazy val withCachedData: LogicalPlan = {
+ assertAnalyzed()
+ cacheManager.useCachedData(analyzed)
+ }
+ lazy val optimizedPlan: LogicalPlan = optimizer.execute(withCachedData)
+
+ // TODO: Don't just pick the first one...
+ lazy val sparkPlan: SparkPlan = {
+ SparkPlan.currentContext.set(sqlContext)
+ planner.plan(optimizedPlan).next()
+ }
+ // executedPlan should not be used to initialize any SparkPlan. It
should be
+ // only used for execution.
+ lazy val executedPlan: SparkPlan = prepareForExecution.execute(sparkPlan)
+
+ /** Internal version of the RDD. Avoids copies and has no schema */
+ lazy val toRdd: RDD[Row] = executedPlan.execute()
+
+ protected def stringOrError[A](f: => A): String =
+ try f.toString catch { case e: Throwable => e.toString }
+
+ def simpleString: String =
+ s"""== Physical Plan ==
+ |${stringOrError(executedPlan)}
+ """.stripMargin.trim
+
+ override def toString: String = {
+ def output =
+ analyzed.output.map(o => s"${o.name}:
${o.dataType.simpleString}").mkString(", ")
+
+ // TODO previously will output RDD details by run
(${stringOrError(toRdd.toDebugString)})
+ // however, the `toRdd` will cause the real execution, which is not
what we want.
+ // We need to think about how to avoid the side effect.
+ s"""== Parsed Logical Plan ==
+ |${stringOrError(logical)}
+ |== Analyzed Logical Plan ==
+ |${stringOrError(output)}
+ |${stringOrError(analyzed)}
+ |== Optimized Logical Plan ==
+ |${stringOrError(optimizedPlan)}
+ |== Physical Plan ==
+ |${stringOrError(executedPlan)}
+ |Code Generation: ${stringOrError(executedPlan.codegenEnabled)}
+ |== RDD ==
+ """.stripMargin.trim
+ }
+}
+
+
+class SparkPlanner(val sqlContext: SQLContext) extends
org.apache.spark.sql.execution.SparkStrategies {
+ val sparkContext: SparkContext = sqlContext.sparkContext
+
+ def codegenEnabled: Boolean = sqlContext.conf.codegenEnabled
+
+ def unsafeEnabled: Boolean = sqlContext.conf.unsafeEnabled
+
+ def numPartitions: Int = sqlContext.conf.numShufflePartitions
+
+ def strategies: Seq[Strategy] =
+ sqlContext.experimental.extraStrategies ++ (
+ DataSourceStrategy ::
+ DDLStrategy ::
+ TakeOrdered ::
+ HashAggregation ::
+ LeftSemiJoin ::
+ HashJoin ::
+ InMemoryScans ::
+ ParquetOperations ::
+ BasicOperators ::
+ CartesianProduct ::
+ BroadcastNestedLoopJoin :: Nil)
+
+ /**
+ * Used to build table scan operators where complex projection and
filtering are done using
+ * separate physical operators. This function returns the given scan
operator with Project and
+ * Filter nodes added only when needed. For example, a Project operator
is only used when the
+ * final desired output requires complex expressions to be evaluated or
when columns can be
+ * further eliminated out after filtering has been done.
+ *
+ * The `prunePushedDownFilters` parameter is used to remove those
filters that can be optimized
+ * away by the filter pushdown optimization.
+ *
+ * The required attributes for both filtering and expression evaluation
are passed to the
+ * provided `scanBuilder` function so that it can avoid unnecessary
column materialization.
+ */
+ def pruneFilterProject(
+ projectList: Seq[NamedExpression],
--- End diff --
4 spaces indent
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]