GitHub user maropu opened a pull request:

    https://github.com/apache/spark/pull/16410

    [SPARK-19005][SQL] Keep column ordering when a schema is explicitly 
specified

    ## What changes were proposed in this pull request?
    This pr is to keep column ordering when a schema is explicitly specified.
    A concrete example is as follows;
    
    ```
    scala> import org.apache.spark.sql.types._
    scala> case class A(a: Long, b: Int)
    scala> val as = Seq(A(1, 2))
    scala> 
spark.createDataFrame(as).write.parquet("/Users/maropu/Desktop/data/a=1/")
    scala> val df = spark.read.parquet("/Users/maropu/Desktop/data/")
    scala> df.printSchema
    root
     |-- a: integer (nullable = true)
     |-- b: integer (nullable = true)
    
    scala> val schema = new StructType().add("a", LongType).add("b", 
IntegerType)
    scala> val df = 
spark.read.schema(schema).parquet("/Users/maropu/Desktop/data/")
    scala> df.printSchema
    root
     |-- b: integer (nullable = true)
     |-- a: long (nullable = true)
    
     ```
    
    This fix removes the code to filter out the overlapped fields of a data 
schema in `getOrInferFileFormatSchema`. Then, it respects column ordering in 
`HadoopFsRelation#schema`.
    
    ## How was this patch tested?
    Added tests in `ParquetPartitionDiscoverySuite` and change some tests in 
`InsertIntoHiveTableSuite` and `MetastoreDataSourcesSuite`.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/maropu/spark SPARK-19005

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/16410.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #16410
    
----
commit 9174e7c0686ddcd963a0232250dbcc50062d750b
Author: Takeshi YAMAMURO <linguin....@gmail.com>
Date:   2016-12-23T13:42:46Z

    Keep column ordering when a schema is explicitly specified

----


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