Skip to content

Commit 1a3c63c

Browse files
committed
Address comments.
1 parent 934d6f1 commit 1a3c63c

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,16 +1196,11 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder(conf) {
11961196

11971197
selectQuery match {
11981198
case Some(q) =>
1199-
// Hive does not allow to use a CTAS statement to create a partitioned table
1200-
// by specifying table schema.
1199+
// When creating partitioned table with CTAS statement, we can't specify data type for the
1200+
// partition columns.
12011201
if (tableDesc.partitionColumnNames.nonEmpty) {
1202-
val errorMessage = "A Create Table As Select (CTAS) statement is not allowed to " +
1203-
"create a partitioned table using Hive's file formats by specifying table schema. " +
1204-
"Please use the syntax of \"CREATE TABLE tableName USING dataSource " +
1205-
"OPTIONS (...) PARTITIONED BY ...\" to create a partitioned table through a " +
1206-
"CTAS statement. You can specify partition column names in CTAS statement like " +
1207-
"\"PARTITIONED BY (col_name, col_name, ...)\" when using Hive's file formats to " +
1208-
"create a partitioned table too."
1202+
val errorMessage = "Create Partitioned Table As Select cannot specify data type for " +
1203+
"the partition columns of the target table."
12091204
operationNotAllowed(errorMessage, ctx)
12101205
}
12111206

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,8 +2381,8 @@ class HiveDDLSuite
23812381
|AS SELECT 1 as a, "a" as b
23822382
""".stripMargin)
23832383
}.getMessage
2384-
assert(err1.contains("A Create Table As Select (CTAS) statement is not allowed " +
2385-
"to create a partitioned table using Hive's file formats by specifying table schema"))
2384+
assert(err1.contains("Create Partitioned Table As Select cannot specify data type for " +
2385+
"the partition columns of the target table"))
23862386

23872387
val err2 = intercept[ParseException] {
23882388
spark.sql(
@@ -2393,8 +2393,8 @@ class HiveDDLSuite
23932393
|AS SELECT 1 as a, "a" as b
23942394
""".stripMargin)
23952395
}.getMessage
2396-
assert(err2.contains("A Create Table As Select (CTAS) statement is not allowed " +
2397-
"to create a partitioned table using Hive's file formats by specifying table schema"))
2396+
assert(err2.contains("Create Partitioned Table As Select cannot specify data type for " +
2397+
"the partition columns of the target table"))
23982398
}
23992399

24002400
test("Hive CTAS with dynamic partition") {
@@ -2410,15 +2410,8 @@ class HiveDDLSuite
24102410
""".stripMargin)
24112411
checkAnswer(spark.table("t"), Row(1, "a"))
24122412

2413-
assert(sql("DESC t").collect().containsSlice(
2414-
Seq(
2415-
Row("a", "int", null),
2416-
Row("b", "string", null),
2417-
Row("# Partition Information", "", ""),
2418-
Row("# col_name", "data_type", "comment"),
2419-
Row("b", "string", null)
2420-
)
2421-
))
2413+
assert(spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
2414+
.partitionColumnNames === Seq("b"))
24222415
}
24232416
}
24242417
}

0 commit comments

Comments
 (0)