aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorgatorsmile <gatorsmile@gmail.com>2016-09-27 10:52:26 -0700
committerHerman van Hovell <hvanhovell@databricks.com>2016-09-27 10:52:26 -0700
commit2ab24a7bf6687ec238306772c4c7ddef6ac93e99 (patch)
tree4426d83e7c804055c5538c7b731e4a0c5b0adf36 /sql
parent120723f934dc386a46a043d2833bfcee60d14e74 (diff)
downloadspark-2ab24a7bf6687ec238306772c4c7ddef6ac93e99.tar.gz
spark-2ab24a7bf6687ec238306772c4c7ddef6ac93e99.tar.bz2
spark-2ab24a7bf6687ec238306772c4c7ddef6ac93e99.zip
[SPARK-17660][SQL] DESC FORMATTED for VIEW Lacks View Definition
### What changes were proposed in this pull request? Before this PR, `DESC FORMATTED` does not have a section for the view definition. We should add it for permanent views, like what Hive does. ``` +----------------------------+-------------------------------------------------------------------------------------------------------------------------------------+-------+ |col_name |data_type |comment| +----------------------------+-------------------------------------------------------------------------------------------------------------------------------------+-------+ |a |int |null | | | | | |# Detailed Table Information| | | |Database: |default | | |Owner: |xiaoli | | |Create Time: |Sat Sep 24 21:46:19 PDT 2016 | | |Last Access Time: |Wed Dec 31 16:00:00 PST 1969 | | |Location: | | | |Table Type: |VIEW | | |Table Parameters: | | | | transient_lastDdlTime |1474778779 | | | | | | |# Storage Information | | | |SerDe Library: |org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe | | |InputFormat: |org.apache.hadoop.mapred.SequenceFileInputFormat | | |OutputFormat: |org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat | | |Compressed: |No | | |Storage Desc Parameters: | | | | serialization.format |1 | | | | | | |# View Information | | | |View Original Text: |SELECT * FROM tbl | | |View Expanded Text: |SELECT `gen_attr_0` AS `a` FROM (SELECT `gen_attr_0` FROM (SELECT `a` AS `gen_attr_0` FROM `default`.`tbl`) AS gen_subquery_0) AS tbl| | +----------------------------+-------------------------------------------------------------------------------------------------------------------------------------+-------+ ``` ### How was this patch tested? Added a test case Author: gatorsmile <gatorsmile@gmail.com> Closes #15234 from gatorsmile/descFormattedView.
Diffstat (limited to 'sql')
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala9
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala19
2 files changed, 28 insertions, 0 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
index 0f61629317..6a91c997ba 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
@@ -462,6 +462,8 @@ case class DescribeTableCommand(table: TableIdentifier, isExtended: Boolean, isF
}
describeStorageInfo(table, buffer)
+
+ if (table.tableType == CatalogTableType.VIEW) describeViewInfo(table, buffer)
}
private def describeStorageInfo(metadata: CatalogTable, buffer: ArrayBuffer[Row]): Unit = {
@@ -479,6 +481,13 @@ case class DescribeTableCommand(table: TableIdentifier, isExtended: Boolean, isF
}
}
+ private def describeViewInfo(metadata: CatalogTable, buffer: ArrayBuffer[Row]): Unit = {
+ append(buffer, "", "", "")
+ append(buffer, "# View Information", "", "")
+ append(buffer, "View Original Text:", metadata.viewOriginalText.getOrElse(""), "")
+ append(buffer, "View Expanded Text:", metadata.viewText.getOrElse(""), "")
+ }
+
private def describeBucketingInfo(metadata: CatalogTable, buffer: ArrayBuffer[Row]): Unit = {
metadata.bucketSpec match {
case Some(BucketSpec(numBuckets, bucketColumnNames, sortColumnNames)) =>
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
index c927e5d802..751e976c7b 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
@@ -506,6 +506,25 @@ class HiveDDLSuite
}
}
+ test("desc formatted table for permanent view") {
+ withTable("tbl") {
+ withView("view1") {
+ sql("CREATE TABLE tbl(a int)")
+ sql("CREATE VIEW view1 AS SELECT * FROM tbl")
+ assert(sql("DESC FORMATTED view1").collect().containsSlice(
+ Seq(
+ Row("# View Information", "", ""),
+ Row("View Original Text:", "SELECT * FROM tbl", ""),
+ Row("View Expanded Text:",
+ "SELECT `gen_attr_0` AS `a` FROM (SELECT `gen_attr_0` FROM " +
+ "(SELECT `a` AS `gen_attr_0` FROM `default`.`tbl`) AS gen_subquery_0) AS tbl",
+ "")
+ )
+ ))
+ }
+ }
+ }
+
test("desc table for data source table using Hive Metastore") {
assume(spark.sparkContext.conf.get(CATALOG_IMPLEMENTATION) == "hive")
val tabName = "tab1"