File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
core/src/main/scala/org/apache/spark/sql/execution
hive/src/test/scala/org/apache/spark/sql/hive/execution Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -1044,10 +1044,13 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
10441044 if (conf.convertCTAS && ! hasStorageProperties) {
10451045 // At here, both rowStorage.serdeProperties and fileStorage.serdeProperties
10461046 // are empty Maps.
1047+ // For data source tables, table properties is only used to store schema and
1048+ // system-generated metadata. All user-specified properties/options will be stored
1049+ // in serde properties.
10471050 val optionsWithPath = if (location.isDefined) {
1048- Map (" path" -> location.get)
1051+ properties ++ Map (" path" -> location.get)
10491052 } else {
1050- Map .empty[ String , String ]
1053+ properties
10511054 }
10521055
10531056 val newTableDesc = tableDesc.copy(
Original file line number Diff line number Diff line change @@ -653,6 +653,20 @@ class HiveDDLSuite
653653 }
654654 }
655655
656+ test(" CTAS - converted to Data Source Table but lost table properties" ) {
657+ withSQLConf(SQLConf .CONVERT_CTAS .key -> " true" ) {
658+ withTable(" t" ) {
659+ sql(" CREATE TABLE t TBLPROPERTIES('prop1' = 'c', 'prop2' = 'd') AS SELECT 1 as a, 1 as b" )
660+ val tableDesc = spark.sessionState.catalog.getTableMetadata(TableIdentifier (" t" ))
661+ assert(tableDesc.properties.get(" prop1" ).isEmpty)
662+ assert(tableDesc.properties.get(" prop2" ).isEmpty)
663+ assert(tableDesc.storage.properties.get(" prop1" ) == Option (" c" ))
664+ assert(tableDesc.storage.properties.get(" prop2" ) == Option (" d" ))
665+ checkAnswer(spark.table(" t" ), Row (1 , 1 ) :: Nil )
666+ }
667+ }
668+ }
669+
656670 test(" desc table for data source table - partitioned bucketed table" ) {
657671 withTable(" t1" ) {
658672 spark
You can’t perform that action at this time.
0 commit comments