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

    https://github.com/apache/spark/pull/17527#discussion_r110317272
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/HadoopFsRelation.scala
 ---
    @@ -52,7 +54,11 @@ case class HadoopFsRelation(
     
       val schema: StructType = {
         val getColName: (StructField => String) =
    -      if (sparkSession.sessionState.conf.caseSensitiveAnalysis) _.name 
else _.name.toLowerCase
    +      if (sparkSession.sessionState.conf.caseSensitiveAnalysis) {
    +        _.name
    +      } else {
    +        _.name.toLowerCase(Locale.ROOT)
    +      }
    --- End diff --
    
    I think we should leave this out. It seems `dataSchema` means the schema 
from the source which is exposed to users. I think this could cause a problem. 
For example as below:
    
    Before
    
    ```scala
    import collection.mutable
    
    import org.apache.spark.sql.types._
    
    java.util.Locale.setDefault(new java.util.Locale("tr"))
    
    val partitionSchema: StructType = StructType(StructField("I", StringType) 
:: Nil)
    val dataSchema: StructType = StructType(StructField("ı", StringType) :: 
Nil)
    
    val getColName: (StructField => String) = _.name.toLowerCase
    
    val overlappedPartCols = mutable.Map.empty[String, StructField]
    partitionSchema.foreach { partitionField =>
      if (dataSchema.exists(getColName(_) == getColName(partitionField))) {
        overlappedPartCols += getColName(partitionField) -> partitionField
      }
    }
    
    val schema = StructType(dataSchema.map(f => 
overlappedPartCols.getOrElse(getColName(f), f)) ++
      partitionSchema.filterNot(f => 
overlappedPartCols.contains(getColName(f))))
    
    schema.fieldNames
    ```
    
    prints
    
    ```scala
    Array[String] = Array(I)
    ```
    
    After
    
    ```scala
    import collection.mutable
    
    import org.apache.spark.sql.types._
    
    java.util.Locale.setDefault(new java.util.Locale("tr"))
    
    val partitionSchema: StructType = StructType(StructField("I", StringType) 
:: Nil)
    val dataSchema: StructType = StructType(StructField("ı", StringType) :: 
Nil)
    
    val getColName: (StructField => String) = 
_.name.toLowerCase(java.util.Locale.ROOT)
    
    val overlappedPartCols = mutable.Map.empty[String, StructField]
    partitionSchema.foreach { partitionField =>
      if (dataSchema.exists(getColName(_) == getColName(partitionField))) {
        overlappedPartCols += getColName(partitionField) -> partitionField
      }
    }
    
    val schema = StructType(dataSchema.map(f => 
overlappedPartCols.getOrElse(getColName(f), f)) ++
      partitionSchema.filterNot(f => 
overlappedPartCols.contains(getColName(f))))
    
    schema.fieldNames
    ```
    
    prints
    
    ```scala
    Array[String] = Array(ı, I)
    ```


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