Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9226#discussion_r43035743
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala ---
    @@ -218,25 +233,19 @@ private[hive] class HiveMetastoreCatalog(val client: 
ClientInterface, hive: Hive
           }
         }
     
    -    val metastorePartitionColumns = userSpecifiedSchema.map { schema =>
    -      val fields = partitionColumns.map(col => schema(col))
    -      fields.map { field =>
    -        HiveColumn(
    -          name = field.name,
    -          hiveType = HiveMetastoreTypes.toMetastoreType(field.dataType),
    -          comment = "")
    -      }.toSeq
    -    }.getOrElse {
    -      if (partitionColumns.length > 0) {
    -        // The table does not have a specified schema, which means that 
the schema will be inferred
    -        // when we load the table. So, we are not expecting partition 
columns and we will discover
    -        // partitions when we load the table. However, if there are 
specified partition columns,
    -        // we simply ignore them and provide a warning message.
    -        logWarning(
    -          s"The schema and partitions of table $tableIdent will be 
inferred when it is loaded. " +
    -            s"Specified partition columns 
(${partitionColumns.mkString(",")}) will be ignored.")
    +    if (userSpecifiedSchema.isDefined && partitionColumns.length > 0) {
    +      tableProperties.put("spark.sql.sources.schema.numPartCols", 
partitionColumns.length.toString)
    +      partitionColumns.zipWithIndex.foreach { case (partCol, index) =>
    +        tableProperties.put(s"spark.sql.sources.schema.partCol.$index", 
partCol)
           }
    -      Seq.empty[HiveColumn]
    +    } else {
    +      // The table does not have a specified schema, which means that the 
schema will be inferred
    +      // when we load the table. So, we are not expecting partition 
columns and we will discover
    +      // partitions when we load the table. However, if there are 
specified partition columns,
    +      // we simply ignore them and provide a warning message.
    +      logWarning(
    +        s"The schema and partitions of table $tableIdent will be inferred 
when it is loaded. " +
    +          s"Specified partition columns 
(${partitionColumns.mkString(",")}) will be ignored.")
    --- End diff --
    
    Seems the condition of this branch is not equivalent to the original one? 
We may hit this branch if the table is not partitioned and there is a 
user-defined schema. 


---
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]

Reply via email to