Skip to content

Commit b5bae84

Browse files
marmbrusrxin
authored andcommitted
[SQL] SPARK-1427 Fix toString for SchemaRDD NativeCommands.
Author: Michael Armbrust <[email protected]> Closes apache#343 from marmbrus/toStringFix and squashes the following commits: 37198fe [Michael Armbrust] Fix toString for SchemaRDD NativeCommands.
1 parent accd099 commit b5bae84

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ class SQLContext(@transient val sparkContext: SparkContext)
224224
protected def stringOrError[A](f: => A): String =
225225
try f.toString catch { case e: Throwable => e.toString }
226226

227+
def simpleString: String = stringOrError(executedPlan)
228+
227229
override def toString: String =
228230
s"""== Logical Plan ==
229231
|${stringOrError(analyzed)}

sql/core/src/main/scala/org/apache/spark/sql/SchemaRDDLike.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ trait SchemaRDDLike {
4141
override def toString =
4242
s"""${super.toString}
4343
|== Query Plan ==
44-
|${queryExecution.executedPlan}""".stripMargin.trim
45-
44+
|${queryExecution.simpleString}""".stripMargin.trim
4645

4746
/**
4847
* Saves the contents of this `SchemaRDD` as a parquet file, preserving the schema. Files that

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,11 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
297297
val asString = result.map(_.zip(types).map(toHiveString)).map(_.mkString("\t")).toSeq
298298
asString
299299
}
300+
301+
override def simpleString: String =
302+
logical match {
303+
case _: NativeCommand => "<Executed by Hive>"
304+
case _ => executedPlan.toString
305+
}
300306
}
301307
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,8 @@ class HiveQuerySuite extends HiveComparisonTest {
146146
hql("SELECT * FROM src TABLESAMPLE(0.1 PERCENT) s")
147147
}
148148

149+
test("SchemaRDD toString") {
150+
hql("SHOW TABLES").toString
151+
hql("SELECT * FROM src").toString
152+
}
149153
}

0 commit comments

Comments
 (0)