Github user liancheng commented on a diff in the pull request:
https://github.com/apache/spark/pull/13756#discussion_r69541353
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
---
@@ -206,7 +207,39 @@ private[sql] case class PreWriteCheck(conf: SQLConf,
catalog: SessionCatalog)
// The relation in l is not an InsertableRelation.
failAnalysis(s"$l does not allow insertion.")
+ case c: CreateTableCommand =>
+ val allColNamesInSchema = c.table.schema.map(_.name)
+ val colNames =
allColNamesInSchema.diff(c.table.partitionColumnNames)
+ val partitionColumnNames = c.table.partitionColumnNames
+ // Duplicates are not allowed in partitionBy
+ // Todo: when bucketBy and sortBy are supported, we also need to
ban the duplication.
+ checkDuplicates(partitionColumnNames, "Partition")
+ // Ensuring whether no duplicate name is used in table definition
+ checkDuplicates(colNames, s"table definition of
${c.table.identifier}")
+ // For non-data-source tables, partition columns must not be part
of the schema
+ val badPartCols =
partitionColumnNames.toSet.intersect(colNames.toSet)
+ if (badPartCols.nonEmpty) {
+ failAnalysis(s"Operation not allowed: Partition columns may not
be specified in the " +
+ "schema: " + badPartCols.map("`" + _ + "`").mkString(","))
+ }
+
+
+ case c: CreateTableUsing =>
+ // Duplicates are not allowed in partitionBy/bucketBy/sortBy
columns.
+ checkDuplicates(c.partitionColumns, "Partition")
+ c.bucketSpec.foreach(b => {
+ checkDuplicates(b.bucketColumnNames, "Bucketing")
+ checkDuplicates(b.sortColumnNames, "Sorting")
+ })
--- End diff --
Use
```scala
foo.foreach { b =>
...
}
```
instead of
```scala
foo.foreach(b => {
...
})
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]