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

    https://github.com/apache/spark/pull/5214#discussion_r27311560
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/parquet/newParquet.scala ---
    @@ -775,6 +777,32 @@ private[sql] object ParquetRelation2 extends Logging {
         })
       }
     
    +  /**
    +   * Returns the original schema from the Parquet file with any missing 
nullable fields from the
    +   * Hive Metastore schema merged in.
    +   *
    +   * When constructing a DataFrame from a collection of structured data, 
the resulting object has
    +   * a schema corresponding to the union of the fields present in each 
element of the collection.
    +   * Spark SQL simply assigns a null value to any field that isn't present 
for a particular row.
    +   * In some cases, it is possible that a given table partition stored as 
a Parquet file doesn't
    +   * contain a particular nullable field in its schema despite that field 
being present in the
    +   * table schema obtained from the Hive Metastore. This method returns a 
schema representing the
    +   * Parquet file schema along with any additional nullable fields from 
the Metastore schema
    +   * merged in.
    +   */
    +  private[parquet] def mergeMissingNullableFields(
    +      metastoreSchema: StructType,
    +      parquetSchema: StructType): StructType = {
    +    val fieldMap = metastoreSchema.map(f => f.name.toLowerCase -> f).toMap
    +    val missingFields = metastoreSchema
    +      .map(_.name.toLowerCase)
    +      .diff(parquetSchema.map(_.name.toLowerCase))
    +      .map(fieldMap(_))
    +      .filter(_.nullable)
    +    StructType(parquetSchema ++ missingFields)
    --- End diff --
    
    What is the expected order of fields in a schema? Is is lexicographic?


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