Skip to content

Commit 5bef1e8

Browse files
committed
revert
1 parent 568f133 commit 5bef1e8

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,12 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
10211021

10221022
selectQuery match {
10231023
case Some(q) =>
1024+
// Just use whatever is projected in the select statement as our schema
1025+
if (schema.nonEmpty) {
1026+
operationNotAllowed(
1027+
"Schema may not be specified in a Create Table As Select (CTAS) statement",
1028+
ctx)
1029+
}
10241030
// Hive does not allow to use a CTAS statement to create a partitioned table.
10251031
if (tableDesc.partitionColumnNames.nonEmpty) {
10261032
val errorMessage = "A Create Table As Select (CTAS) statement is not allowed to " +
@@ -1030,12 +1036,6 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
10301036
"CTAS statement."
10311037
operationNotAllowed(errorMessage, ctx)
10321038
}
1033-
// Just use whatever is projected in the select statement as our schema
1034-
if (schema.nonEmpty) {
1035-
operationNotAllowed(
1036-
"Schema may not be specified in a Create Table As Select (CTAS) statement",
1037-
ctx)
1038-
}
10391039

10401040
val hasStorageProperties = (ctx.createFileFormat != null) || (ctx.rowFormat != null)
10411041
if (conf.convertCTAS && !hasStorageProperties) {

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

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -625,35 +625,19 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
625625
}
626626

627627
test("specifying the column list for CTAS") {
628-
withTempTable("mytable1") {
629-
Seq((1, "111111"), (2, "222222")).toDF("key", "value").createOrReplaceTempView("mytable1")
630-
withTable("gen__tmp") {
631-
sql("create table gen__tmp as select key as a, value as b from mytable1")
632-
checkAnswer(
633-
sql("SELECT a, b from gen__tmp"),
634-
sql("select key, value from mytable1").collect())
635-
}
628+
Seq((1, "111111"), (2, "222222")).toDF("key", "value").createOrReplaceTempView("mytable1")
636629

637-
withTable("gen__tmp") {
638-
val e = intercept[AnalysisException] {
639-
sql("create table gen__tmp(a int, b string) as select key, value from mytable1")
640-
}.getMessage
641-
assert(e.contains("Schema may not be specified in a Create Table As Select (CTAS)"))
642-
}
630+
sql("create table gen__tmp as select key as a, value as b from mytable1")
631+
checkAnswer(
632+
sql("SELECT a, b from gen__tmp"),
633+
sql("select key, value from mytable1").collect())
634+
sql("DROP TABLE gen__tmp")
643635

644-
withTable("gen__tmp") {
645-
val e = intercept[AnalysisException] {
646-
sql(
647-
"""
648-
|CREATE TABLE gen__tmp
649-
|PARTITIONED BY (key string)
650-
|AS SELECT key, value FROM mytable1
651-
""".stripMargin)
652-
}.getMessage
653-
assert(e.contains("A Create Table As Select (CTAS) statement is not allowed to " +
654-
"create a partitioned table using Hive's file formats"))
655-
}
636+
intercept[AnalysisException] {
637+
sql("create table gen__tmp(a int, b string) as select key, value from mytable1")
656638
}
639+
640+
sql("drop table mytable1")
657641
}
658642

659643
test("command substitution") {

0 commit comments

Comments
 (0)