Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14482#discussion_r73469309
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala 
---
    @@ -62,6 +66,122 @@ private[sql] class ResolveDataSource(sparkSession: 
SparkSession) extends Rule[Lo
     }
     
     /**
    + * Preprocess some DDL plans, e.g. [[CreateTable]], to do some 
normalization and checking.
    + */
    +case class PreprocessDDL(conf: SQLConf) extends Rule[LogicalPlan] {
    +
    +  def apply(plan: LogicalPlan): LogicalPlan = plan transform {
    +    // When we CREATE TABLE without specifying the table schema, we should 
fail the query if
    +    // bucketing information is specified, as we can't infer bucketing 
from data files currently,
    +    // and we should ignore the partition columns if it's specified, as we 
will infer it later, at
    +    // runtime.
    +    case c @ CreateTable(tableDesc, _, None) if tableDesc.schema.isEmpty =>
    +      if (tableDesc.bucketSpec.isDefined) {
    +        failAnalysis("Cannot specify bucketing information if the table 
schema is not specified " +
    +          "when creating and will be inferred at runtime")
    +      }
    +
    +      val partitionColumnNames = tableDesc.partitionColumnNames
    +      if (partitionColumnNames.nonEmpty) {
    +        // The table does not have a specified schema, which means that 
the schema will be inferred
    +        // at runtime. So, we are not expecting partition columns and we 
will discover partitions
    +        // at runtime. However, if there are specified partition columns, 
we simply ignore them and
    +        // provide a warning message.
    +        logWarning(
    +          s"Specified partition columns 
(${partitionColumnNames.mkString(",")}) will be " +
    +            s"ignored. The schema and partition columns of table 
${tableDesc.identifier} will " +
    +            "be inferred.")
    +        c.copy(tableDesc = tableDesc.copy(partitionColumnNames = Nil))
    +      } else {
    +        c
    +      }
    +
    +    // Here we normalize partition, bucket and sort column names, w.r.t. 
the case sensitivity
    +    // config, and do various checks:
    +    //   * column names in table definition can't be duplicated.
    +    //   * partition, bucket and sort column names must exist in table 
definition.
    +    //   * partition, bucket and sort column names can't be duplicated.
    +    //   * can't use all table columns as partition columns.
    +    //   * partition columns' type must be AtomicType.
    +    //   * sort columns' type must be orderable.
    --- End diff --
    
    because hive CREATE TABLE syntax is special, it will never hit this 
exception `partition column names must exist in table definition.` Instead, 
hive may specify partition column names that exist in table definition, and 
will hit `column names in table definition can't be duplicated`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to