From 56b62b070a8ced9908454854d00f276b988a49c4 Mon Sep 17 00:00:00 2001 From: PengLei Date: Fri, 28 Jan 2022 10:10:29 +0800 Subject: [PATCH] add draft --- .../spark/sql/execution/command/tables.scala | 4 ++-- .../sql-tests/results/charvarchar.sql.out | 4 ++-- .../results/show-create-table.sql.out | 24 +++++++++---------- .../sql/execution/SQLViewTestSuite.scala | 6 ++--- 4 files changed, 19 insertions(+), 19 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 7ae0e017b28c..eceb9e6536d5 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 @@ -35,7 +35,7 @@ import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec import org.apache.spark.sql.catalyst.expressions.Attribute import org.apache.spark.sql.catalyst.plans.DescribeCommandSchema import org.apache.spark.sql.catalyst.plans.logical._ -import org.apache.spark.sql.catalyst.util.{escapeSingleQuotedString, quoteIdentifier, CaseInsensitiveMap, CharVarcharUtils} +import org.apache.spark.sql.catalyst.util.{escapeSingleQuotedString, quoteIfNeeded, CaseInsensitiveMap, CharVarcharUtils} import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.TableIdentifierHelper import org.apache.spark.sql.errors.{QueryCompilationErrors, QueryExecutionErrors} import org.apache.spark.sql.execution.datasources.DataSource @@ -1035,7 +1035,7 @@ trait ShowCreateTableCommandBase { .map(" COMMENT '" + _ + "'") // view columns shouldn't have data type info - s"${quoteIdentifier(f.name)}${comment.getOrElse("")}" + s"${quoteIfNeeded(f.name)}${comment.getOrElse("")}" } builder ++= concatByMultiLines(viewColumns) } diff --git a/sql/core/src/test/resources/sql-tests/results/charvarchar.sql.out b/sql/core/src/test/resources/sql-tests/results/charvarchar.sql.out index de994d67c9f3..6345702e00ea 100644 --- a/sql/core/src/test/resources/sql-tests/results/charvarchar.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/charvarchar.sql.out @@ -219,8 +219,8 @@ show create table char_view struct -- !query output CREATE VIEW default.char_view ( - `c`, - `v`) + c, + v) AS select * from char_tbl diff --git a/sql/core/src/test/resources/sql-tests/results/show-create-table.sql.out b/sql/core/src/test/resources/sql-tests/results/show-create-table.sql.out index 4c7f124e72fe..ca1652b337a2 100644 --- a/sql/core/src/test/resources/sql-tests/results/show-create-table.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/show-create-table.sql.out @@ -296,8 +296,8 @@ SHOW CREATE TABLE view_SPARK_30302 AS SERDE struct -- !query output CREATE VIEW default.view_SPARK_30302 ( - `aaa`, - `bbb`) + aaa, + bbb) AS SELECT a, b FROM tbl @@ -307,8 +307,8 @@ SHOW CREATE TABLE view_SPARK_30302 struct -- !query output CREATE VIEW default.view_SPARK_30302 ( - `aaa`, - `bbb`) + aaa, + bbb) AS SELECT a, b FROM tbl @@ -336,8 +336,8 @@ SHOW CREATE TABLE view_SPARK_30302 AS SERDE struct -- !query output CREATE VIEW default.view_SPARK_30302 ( - `aaa` COMMENT 'comment with \'quoted text\' for aaa', - `bbb`) + aaa COMMENT 'comment with \'quoted text\' for aaa', + bbb) COMMENT 'This is a comment with \'quoted text\' for view' AS SELECT a, b FROM tbl @@ -348,8 +348,8 @@ SHOW CREATE TABLE view_SPARK_30302 struct -- !query output CREATE VIEW default.view_SPARK_30302 ( - `aaa` COMMENT 'comment with \'quoted text\' for aaa', - `bbb`) + aaa COMMENT 'comment with \'quoted text\' for aaa', + bbb) COMMENT 'This is a comment with \'quoted text\' for view' AS SELECT a, b FROM tbl @@ -378,8 +378,8 @@ SHOW CREATE TABLE view_SPARK_30302 AS SERDE struct -- !query output CREATE VIEW default.view_SPARK_30302 ( - `aaa`, - `bbb`) + aaa, + bbb) TBLPROPERTIES ( 'a' = '1', 'b' = '2') @@ -392,8 +392,8 @@ SHOW CREATE TABLE view_SPARK_30302 struct -- !query output CREATE VIEW default.view_SPARK_30302 ( - `aaa`, - `bbb`) + aaa, + bbb) TBLPROPERTIES ( 'a' = '1', 'b' = '2') diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewTestSuite.scala index da6826c7808a..94855f2c4214 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewTestSuite.scala @@ -611,7 +611,7 @@ class PersistedViewTestSuite extends SQLViewTestSuite with SharedSparkSession { Seq(true, false).foreach { serde => withView(viewName) { createView(viewName, "SELECT 1 AS a") - val expected = s"CREATE VIEW ${formattedViewName(viewName)} ( `a`) AS SELECT 1 AS a" + val expected = s"CREATE VIEW ${formattedViewName(viewName)} ( a) AS SELECT 1 AS a" assert(getShowCreateDDL(formattedViewName(viewName), serde) == expected) } } @@ -623,7 +623,7 @@ class PersistedViewTestSuite extends SQLViewTestSuite with SharedSparkSession { withView(viewName) { createView(viewName, "SELECT 1 AS a, 2 AS b", Seq("a", "b COMMENT 'b column'")) val expected = s"CREATE VIEW ${formattedViewName(viewName)}" + - s" ( `a`, `b` COMMENT 'b column') AS SELECT 1 AS a, 2 AS b" + s" ( a, b COMMENT 'b column') AS SELECT 1 AS a, 2 AS b" assert(getShowCreateDDL(formattedViewName(viewName), serde) == expected) } } @@ -636,7 +636,7 @@ class PersistedViewTestSuite extends SQLViewTestSuite with SharedSparkSession { createView(viewName, "SELECT 1 AS c1, '2' AS c2", Seq("c1 COMMENT 'bla'", "c2"), Seq("COMMENT 'table comment'", "TBLPROPERTIES ( 'prop2' = 'value2', 'prop1' = 'value1')")) - val expected = s"CREATE VIEW ${formattedViewName(viewName)} ( `c1` COMMENT 'bla', `c2`)" + + val expected = s"CREATE VIEW ${formattedViewName(viewName)} ( c1 COMMENT 'bla', c2)" + " COMMENT 'table comment'" + " TBLPROPERTIES ( 'prop1' = 'value1', 'prop2' = 'value2')" + " AS SELECT 1 AS c1, '2' AS c2"