Skip to content

Commit 237b96b

Browse files
lianchengrxin
authored andcommitted
Minor fix: made "EXPLAIN" output to play well with JDBC output format
Fixed the broken JDBC output. Test from Shark `beeline`: ``` beeline> !connect jdbc:hive2://localhost:10000/ scan complete in 2ms Connecting to jdbc:hive2://localhost:10000/ Enter username for jdbc:hive2://localhost:10000/: lian Enter password for jdbc:hive2://localhost:10000/: Connected to: Hive (version 0.12.0) Driver: Hive (version 0.12.0) Transaction isolation: TRANSACTION_REPEATABLE_READ 0: jdbc:hive2://localhost:10000/> 0: jdbc:hive2://localhost:10000/> explain select * from src; +-------------------------------------------------------------------------------+ | plan | +-------------------------------------------------------------------------------+ | ExplainCommand [plan#2:0] | | HiveTableScan [key#0,value#1], (MetastoreRelation default, src, None), None | +-------------------------------------------------------------------------------+ 2 rows selected (1.386 seconds) ``` Before this change, the output looked something like this: ``` +-------------------------------------------------------------------------------+ | plan | +-------------------------------------------------------------------------------+ | ExplainCommand [plan#2:0] HiveTableScan [key#0,value#1], (MetastoreRelation default, src, None), None | +-------------------------------------------------------------------------------+ ``` Author: Cheng Lian <[email protected]> Closes #1097 from liancheng/multiLineExplain and squashes the following commits: eb37967 [Cheng Lian] Made output of "EXPLAIN" play well with JDBC output format
1 parent 273afcb commit 237b96b

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/commands.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ case class ExplainCommand(
8383
override protected[sql] lazy val sideEffectResult: Seq[String] = this.toString.split("\n")
8484

8585
def execute(): RDD[Row] = {
86-
val explanation = sideEffectResult.mkString("\n")
87-
context.sparkContext.parallelize(Seq(new GenericRow(Array[Any](explanation))), 1)
86+
val explanation = sideEffectResult.map(row => new GenericRow(Array[Any](row)))
87+
context.sparkContext.parallelize(explanation, 1)
8888
}
8989

9090
override def otherCopyArgs = context :: Nil

sql/hive/src/test/scala/org/apache/spark/sql/hive/api/java/JavaHiveQLSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class JavaHiveQLSuite extends FunSuite {
4949

5050
def isExplanation(result: JavaSchemaRDD) = {
5151
val explanation = result.collect().map(_.getString(0))
52-
explanation.size == 1 && explanation.head.startsWith(explainCommandClassName)
52+
explanation.size > 1 && explanation.head.startsWith(explainCommandClassName)
5353
}
5454

5555
ignore("Query Hive native command execution result") {

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class HiveQuerySuite extends HiveComparisonTest {
169169

170170
def isExplanation(result: SchemaRDD) = {
171171
val explanation = result.select('plan).collect().map { case Row(plan: String) => plan }
172-
explanation.size == 1 && explanation.head.startsWith(explainCommandClassName)
172+
explanation.size > 1 && explanation.head.startsWith(explainCommandClassName)
173173
}
174174

175175
test("SPARK-1704: Explain commands as a SchemaRDD") {

0 commit comments

Comments
 (0)