GitHub user maropu opened a pull request:
https://github.com/apache/spark/pull/16030
[SPARK-18108][SQL] Fix a bug to fail partition schema inference
## What changes were proposed in this pull request?
This pr is to fix a bug to fail partition schema inference;
```
scala> case class A(a: Long, b: Int)
scala> val as = Seq(A(1, 2))
scala> spark.createDataFrame(as).write.parquet("/data/a=1/")
scala> val df = spark.read.parquet("/data/")
scala> df.printSchema
root
|-- a: long (nullable = true)
|-- b: integer (nullable = true)
scala> df.collect
java.lang.NullPointerException
at
org.apache.spark.sql.execution.vectorized.OnHeapColumnVector.getLong(OnHeapColumnVector.java:283)
at
org.apache.spark.sql.execution.vectorized.ColumnarBatch$Row.getLong(ColumnarBatch.java:191)
at
org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.apply(Unknown
Source)
at
org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.apply(Unknown
Source)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:409)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:409)
```
This was because spark failed to infer the partition column as `LongType`
and it wrongly regarded the column as `IntegerType` in `DataSource`.
Therefore, the query failed in scanning the column from a parquet file.
## How was this patch tested?
Add tests in `ParquetPartitionDiscoverySuite`
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/maropu/spark SPARK-18108
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/16030.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 #16030
----
commit 6bd8b4cdb63b20bc292a5ec1d8ca38281ee5bfbf
Author: Takeshi YAMAMURO <[email protected]>
Date: 2016-11-28T07:45:30Z
Fix a bug to fail partition schema inference
----
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]