opensky142857 commented on a change in pull request #32675:
URL: https://github.com/apache/spark/pull/32675#discussion_r649826784



##########
File path: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
##########
@@ -1092,14 +1092,23 @@ private[hive] object HiveClientImpl extends Logging {
       hiveTable.setViewExpandedText(t)
     }
 
+    // hive may convert schema into lower cases while bucketSpec will not
+    // only convert if case not match
+    def restoreHiveBucketSpecColNames(schema: StructType, names: Seq[String]): 
Seq[String] = {
+      names.map { name =>
+        schema.find(col => SQLConf.get.resolver(col.name, 
name)).map(_.name).getOrElse(name)
+      }
+    }
+
     table.bucketSpec match {
       case Some(bucketSpec) if !HiveExternalCatalog.isDatasourceTable(table) =>
         hiveTable.setNumBuckets(bucketSpec.numBuckets)
-        hiveTable.setBucketCols(bucketSpec.bucketColumnNames.toList.asJava)
+        hiveTable.setBucketCols(
+          restoreHiveBucketSpecColNames(table.schema, 
bucketSpec.bucketColumnNames).toList.asJava)
 
         if (bucketSpec.sortColumnNames.nonEmpty) {
           hiveTable.setSortCols(
-            bucketSpec.sortColumnNames
+            restoreHiveBucketSpecColNames(table.schema, 
bucketSpec.sortColumnNames)

Review comment:
       org/apache/spark/sql/hive/client/HiveClient.scala
   final def getPartitions(
         db: String,
         table: String,
         partialSpec: Option[TablePartitionSpec]): Seq[CatalogTablePartition] = 
{
       getPartitions(getTable(db, table), partialSpec)
     }
   
   in this method, we get table from metasotre and pass it into getPartitions
   and then call toHiveTable to convert a catalog table into HiveTable.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to