Skip to content

Commit 48ddb08

Browse files
committed
fix
1 parent 472f161 commit 48ddb08

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,13 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
937937

938938
selectQuery match {
939939
case Some(q) => CreateTableAsSelectLogicalPlan(tableDesc, q, ifNotExists)
940-
case None => CreateTableCommand(tableDesc, ifNotExists)
940+
case None =>
941+
val partitionColsInTable = partitionCols.map(_.name).toSet.intersect(cols.map(_.name).toSet)
942+
if (partitionColsInTable.nonEmpty) {
943+
throw new ParseException(s"Column repeated in partitioning columns: " +
944+
partitionColsInTable.mkString("[", ",", "]"), ctx)
945+
}
946+
CreateTableCommand(tableDesc, ifNotExists)
941947
}
942948
}
943949

sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLCommandSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ class DDLCommandSuite extends PlanTest {
319319
assert(ct.table.storage.locationUri == Some("/something/anything"))
320320
}
321321

322+
test("create table - column repeated in partitioning columns") {
323+
val query = "CREATE TABLE tab1 (key INT, value STRING) PARTITIONED BY (key INT, hr STRING)"
324+
val e = intercept[ParseException] { parser.parsePlan(query) }
325+
assert(e.getMessage.contains("Column repeated in partitioning columns: [key]"))
326+
}
327+
322328
test("create table using - with partitioned by") {
323329
val query = "CREATE TABLE my_tab(a INT, b STRING) USING parquet PARTITIONED BY (a)"
324330
val expected = CreateTableUsing(

0 commit comments

Comments
 (0)