This is an automated email from the ASF dual-hosted git repository. dongjoon pushed a commit to branch branch-3.3 in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.3 by this push: new 0487e8130d5 [SPARK-40829][SQL] STORED AS serde in CREATE TABLE LIKE view does not work 0487e8130d5 is described below commit 0487e8130d502f62288721c00731511525868976 Author: zhangbutao <zhangbu...@cmss.chinamobile.com> AuthorDate: Tue Oct 18 14:54:39 2022 -0700 [SPARK-40829][SQL] STORED AS serde in CREATE TABLE LIKE view does not work ### What changes were proposed in this pull request? After [SPARK-29839](https://issues.apache.org/jira/browse/SPARK-29839), we could create a table with specife based a existing view, but the serde of created is always parquet. However, if we use USING syntax ([SPARK-29421](https://issues.apache.org/jira/browse/SPARK-29421)) to create a table with specified serde based a view, we can get the correct serde. ### Why are the changes needed? We should add specified serde for the created table when using `create table like view stored as` syntax. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Unit Test Closes #38295 from zhangbutao/SPARK-40829. Authored-by: zhangbutao <zhangbu...@cmss.chinamobile.com> Signed-off-by: Dongjoon Hyun <dongj...@apache.org> (cherry picked from commit 4ad29829bf53fff26172845312b334008bc4cb68) Signed-off-by: Dongjoon Hyun <dongj...@apache.org> --- .../apache/spark/sql/execution/command/tables.scala | 4 ++-- .../apache/spark/sql/hive/execution/HiveDDLSuite.scala | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 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 ac4bb8395a3..60f43ca0ff4 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 @@ -95,10 +95,10 @@ case class CreateTableLikeCommand( DataSource.lookupDataSource(provider.get, sparkSession.sessionState.conf) } provider - } else if (sourceTableDesc.tableType == CatalogTableType.VIEW) { - Some(sparkSession.sessionState.conf.defaultDataSourceName) } else if (fileFormat.inputFormat.isDefined) { Some(DDLUtils.HIVE_PROVIDER) + } else if (sourceTableDesc.tableType == CatalogTableType.VIEW) { + Some(sparkSession.sessionState.conf.defaultDataSourceName) } else { sourceTableDesc.provider } 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 c4cef44b6cc..c3e16e02941 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 @@ -2750,6 +2750,24 @@ class HiveDDLSuite } } + test("Create Table LIKE VIEW STORED AS Hive Format") { + val catalog = spark.sessionState.catalog + withView("v") { + sql("CREATE TEMPORARY VIEW v AS SELECT 1 AS A, 1 AS B;") + hiveFormats.foreach { tableType => + val expectedSerde = HiveSerDe.sourceToSerDe(tableType) + withTable("t") { + sql(s"CREATE TABLE t LIKE v STORED AS $tableType") + val table = catalog.getTableMetadata(TableIdentifier("t")) + assert(table.provider == Some("hive")) + assert(table.storage.serde == expectedSerde.get.serde) + assert(table.storage.inputFormat == expectedSerde.get.inputFormat) + assert(table.storage.outputFormat == expectedSerde.get.outputFormat) + } + } + } + } + test("Create Table LIKE with specified TBLPROPERTIES") { val catalog = spark.sessionState.catalog withTable("s", "t") { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org