GitHub user kiszk opened a pull request:
https://github.com/apache/spark/pull/17293
[SPARK-19950][SQL] Fix to ignore nullable when df.load() is executed for
file-based data source
## What changes were proposed in this pull request?
This PR fixes a problem that was reported in [Databricks
forum](https://forums.databricks.com/questions/7123/nullable-seemingly-ignored-when-reading-parquet.html).
When the following code is executed, a schema for ``id`` has ``nullable =
true`` while `read.schema()` specifies ``nullable = false``.
I realized this is because current Spark sets `true` into ``nullable`` in
its schema for file-based data source. I fixed this conservative setting.
```java
val field = "id"
val df = spark.range(0, 5, 1, 1).toDF(field)
val fmt = "parquet"
val path = "/tmp/parquet"
val schema = StructType(Seq(StructField(field, LongType, false)))
df.write.format(fmt).mode("overwrite").save(path)
val dfRead = spark.read.format(fmt).schema(schema).load(path)
dfRead.printSchema
```
## How was this patch tested?
added new test in `DataFrameSuite`
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/kiszk/spark SPARK-19950
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/17293.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 #17293
----
commit e36bb0bb8b19d9951f81c431969732ec3f79fd51
Author: Kazuaki Ishizaki <[email protected]>
Date: 2017-03-14T16:14:49Z
initial commit
----
---
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]