aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/main/scala/org/apache
diff options
context:
space:
mode:
authorLiang-Chi Hsieh <simonh@tw.ibm.com>2016-04-22 09:19:36 -0700
committerDavies Liu <davies.liu@gmail.com>2016-04-22 09:19:36 -0700
commit056883e070bd258d193fd4d783ab608a19b86c36 (patch)
tree7072659655b15b2ed60c809efcd7af5c2b002e88 /sql/core/src/main/scala/org/apache
parent5bed13a872dc06d099c810cf4caa15b4f27a1e7c (diff)
downloadspark-056883e070bd258d193fd4d783ab608a19b86c36.tar.gz
spark-056883e070bd258d193fd4d783ab608a19b86c36.tar.bz2
spark-056883e070bd258d193fd4d783ab608a19b86c36.zip
[SPARK-13266] [SQL] None read/writer options were not transalated to "null"
## What changes were proposed in this pull request? In Python, the `option` and `options` method of `DataFrameReader` and `DataFrameWriter` were sending the string "None" instead of `null` when passed `None`, therefore making it impossible to send an actual `null`. This fixes that problem. This is based on #11305 from mathieulongtin. ## How was this patch tested? Added test to readwriter.py. Author: Liang-Chi Hsieh <simonh@tw.ibm.com> Author: mathieu longtin <mathieu.longtin@nuance.com> Closes #12494 from viirya/py-df-none-option.
Diffstat (limited to 'sql/core/src/main/scala/org/apache')
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala6
1 files changed, 5 insertions, 1 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala
index 7b9d3b605a..80a0ad7856 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala
@@ -29,6 +29,7 @@ private[sql] class CSVOptions(@transient private val parameters: Map[String, Str
val paramValue = parameters.get(paramName)
paramValue match {
case None => default
+ case Some(null) => default
case Some(value) if value.length == 0 => '\u0000'
case Some(value) if value.length == 1 => value.charAt(0)
case _ => throw new RuntimeException(s"$paramName cannot be more than one character")
@@ -39,6 +40,7 @@ private[sql] class CSVOptions(@transient private val parameters: Map[String, Str
val paramValue = parameters.get(paramName)
paramValue match {
case None => default
+ case Some(null) => default
case Some(value) => try {
value.toInt
} catch {
@@ -50,7 +52,9 @@ private[sql] class CSVOptions(@transient private val parameters: Map[String, Str
private def getBool(paramName: String, default: Boolean = false): Boolean = {
val param = parameters.getOrElse(paramName, default.toString)
- if (param.toLowerCase == "true") {
+ if (param == null) {
+ default
+ } else if (param.toLowerCase == "true") {
true
} else if (param.toLowerCase == "false") {
false