Github user zheyuan28 commented on a diff in the pull request: https://github.com/apache/spark/pull/22458#discussion_r220257132 --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala --- @@ -2348,4 +2348,17 @@ class HiveDDLSuite } } } + + test("desc formatted table should also show viewOriginalText for views") { + withView("v1") { + sql("CREATE VIEW v1 AS SELECT 1 AS value") + assert(sql("DESC FORMATTED v1").collect().containsSlice( + Seq( + Row("Type", "VIEW", ""), + Row("View Text", "SELECT 1 AS value", ""), + Row("View Original Text:", "SELECT 1 AS value", "") --- End diff -- @MaxGekk @gatorsmile Sorry for late, I was trying to use hive client to create the older view. But I find the [toHiveTable](https://github.com/apache/spark/blob/master/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala#L918) method will always use the expanded view text when I create view: https://github.com/apache/spark/blob/master/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala#L955. Is that reasonable we change that to: ```scala table.viewText.foreach { t => hiveTable.setViewExpandedText(t) } table.viewOriginalText.foreach { t => hiveTable.setViewOriginalText(t) } ``` Here is my new test case: ```scala test("SPARK-25459 desc formatted table for views created by older Spark") { withTable("hive_table") { withView("old_view") { spark.sql("CREATE TABLE hive_table AS SELECT 1 AS a, 2 AS b") val expandedView = "SELECT `gen_attr_0` AS `a`, `gen_attr_1` AS `b` FROM (SELECT " + "`gen_attr_0`, `gen_attr_1` FROM (SELECT `a` AS `gen_attr_0`, `b` AS " + "`gen_attr_1` FROM hive_table) AS gen_subquery_0) AS hive_table" val view = CatalogTable( identifier = TableIdentifier("old_view"), tableType = CatalogTableType.VIEW, storage = CatalogStorageFormat.empty, schema = new StructType().add("a", "int").add("b", "int"), viewText = Some(expandedView), viewOriginalText = Some("SELECT 1 AS a, 2 AS b") ) hiveContext.sessionState.catalog.createTable(view, ignoreIfExists = false) // Check the output rows. assert(sql("DESC FORMATTED old_view").collect().containsSlice( Seq( Row("Type", "VIEW", ""), Row("View Text", expandedView, ""), Row("View Original Text", "SELECT 1 AS a, 2 AS b", "") ) )) } } } ```
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org