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

    https://github.com/apache/spark/pull/5298#discussion_r28205982
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableSupport.scala 
---
    @@ -98,12 +98,32 @@ private[parquet] class RowReadSupport extends 
ReadSupport[Row] with Logging {
         val metadata = new JHashMap[String, String]()
         val requestedAttributes = 
RowReadSupport.getRequestedSchema(configuration)
     
    +    // convert fileSchema to attributes
    +    val fileAttributes = 
ParquetTypesConverter.convertToAttributes(fileSchema, true, true)
    +    val fileAttMap = fileAttributes.map(f => f.name.toLowerCase -> 
f.name).toMap
    +
         if (requestedAttributes != null) {
    +      // reconcile names of requested Attributes
    +      val modRequestedAttributes = requestedAttributes.map(attr => {
    +      val lName = attr.name.toLowerCase
    +      if (fileAttMap.contains(lName)) {
    +        attr.withName(fileAttMap(lName))
    +      } else {
    +        if (attr.nullable) {
    +          attr
    +        } else {
    +          // field is not nullable but not present in the parquet file 
schema!!
    +          // this is just a safety check since in hive all columns are 
nullable
    +          // throw exception here
    +          throw new RuntimeException(s"""Field ${attr.name} is 
non-nullable, 
    +            but not found in parquet file schema: 
${fileSchema}""".stripMargin)
    +        }}})
    +
    --- End diff --
    
    Are we essentially duplicating 
`ParquetRelation2.mergeMetastoreParquetSchema` here?


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