Skip to content
Snippets Groups Projects
Commit 3ca995b7 authored by Yijie Shen's avatar Yijie Shen Committed by Yin Huai
Browse files

[SPARK-6212] [SQL] The EXPLAIN output of CTAS only shows the analyzed plan

JIRA: https://issues.apache.org/jira/browse/SPARK-6212

Author: Yijie Shen <henry.yijieshen@gmail.com>

Closes #7986 from yjshen/ctas_explain and squashes the following commits:

bb6fee5 [Yijie Shen] refine test
f731041 [Yijie Shen] address comment
b2cf8ab [Yijie Shen] bug fix
bd7eb20 [Yijie Shen] ctas explain
parent 25c363e9
No related branches found
No related tags found
No related merge requests found
...@@ -69,6 +69,8 @@ private[sql] case class ExecutedCommand(cmd: RunnableCommand) extends SparkPlan ...@@ -69,6 +69,8 @@ private[sql] case class ExecutedCommand(cmd: RunnableCommand) extends SparkPlan
val converted = sideEffectResult.map(convert(_).asInstanceOf[InternalRow]) val converted = sideEffectResult.map(convert(_).asInstanceOf[InternalRow])
sqlContext.sparkContext.parallelize(converted, 1) sqlContext.sparkContext.parallelize(converted, 1)
} }
override def argString: String = cmd.toString
} }
/** /**
......
...@@ -40,6 +40,8 @@ case class CreateTableAsSelect( ...@@ -40,6 +40,8 @@ case class CreateTableAsSelect(
def database: String = tableDesc.database def database: String = tableDesc.database
def tableName: String = tableDesc.name def tableName: String = tableDesc.name
override def children: Seq[LogicalPlan] = Seq(query)
override def run(sqlContext: SQLContext): Seq[Row] = { override def run(sqlContext: SQLContext): Seq[Row] = {
val hiveContext = sqlContext.asInstanceOf[HiveContext] val hiveContext = sqlContext.asInstanceOf[HiveContext]
lazy val metastoreRelation: MetastoreRelation = { lazy val metastoreRelation: MetastoreRelation = {
...@@ -91,6 +93,6 @@ case class CreateTableAsSelect( ...@@ -91,6 +93,6 @@ case class CreateTableAsSelect(
} }
override def argString: String = { override def argString: String = {
s"[Database:$database, TableName: $tableName, InsertIntoHiveTable]\n" + query.toString s"[Database:$database, TableName: $tableName, InsertIntoHiveTable]"
} }
} }
...@@ -17,13 +17,18 @@ ...@@ -17,13 +17,18 @@
package org.apache.spark.sql.hive.execution package org.apache.spark.sql.hive.execution
import org.apache.spark.sql.QueryTest import org.apache.spark.sql.{SQLContext, QueryTest}
import org.apache.spark.sql.hive.test.TestHive
import org.apache.spark.sql.hive.test.TestHive._ import org.apache.spark.sql.hive.test.TestHive._
import org.apache.spark.sql.test.SQLTestUtils
/** /**
* A set of tests that validates support for Hive Explain command. * A set of tests that validates support for Hive Explain command.
*/ */
class HiveExplainSuite extends QueryTest { class HiveExplainSuite extends QueryTest with SQLTestUtils {
def sqlContext: SQLContext = TestHive
test("explain extended command") { test("explain extended command") {
checkExistence(sql(" explain select * from src where key=123 "), true, checkExistence(sql(" explain select * from src where key=123 "), true,
"== Physical Plan ==") "== Physical Plan ==")
...@@ -74,4 +79,30 @@ class HiveExplainSuite extends QueryTest { ...@@ -74,4 +79,30 @@ class HiveExplainSuite extends QueryTest {
"Limit", "Limit",
"src") "src")
} }
test("SPARK-6212: The EXPLAIN output of CTAS only shows the analyzed plan") {
withTempTable("jt") {
val rdd = sparkContext.parallelize((1 to 10).map(i => s"""{"a":$i, "b":"str$i"}"""))
read.json(rdd).registerTempTable("jt")
val outputs = sql(
s"""
|EXPLAIN EXTENDED
|CREATE TABLE t1
|AS
|SELECT * FROM jt
""".stripMargin).collect().map(_.mkString).mkString
val shouldContain =
"== Parsed Logical Plan ==" :: "== Analyzed Logical Plan ==" :: "Subquery" ::
"== Optimized Logical Plan ==" :: "== Physical Plan ==" ::
"CreateTableAsSelect" :: "InsertIntoHiveTable" :: "jt" :: Nil
for (key <- shouldContain) {
assert(outputs.contains(key), s"$key doesn't exist in result")
}
val physicalIndex = outputs.indexOf("== Physical Plan ==")
assert(!outputs.substring(physicalIndex).contains("Subquery"),
"Physical Plan should not contain Subquery since it's eliminated by optimizer")
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment