aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/pyspark/sql/tests.py7
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/types/Metadata.scala7
2 files changed, 13 insertions, 1 deletions
diff --git a/python/pyspark/sql/tests.py b/python/pyspark/sql/tests.py
index 7593b991a7..410efbafe0 100644
--- a/python/pyspark/sql/tests.py
+++ b/python/pyspark/sql/tests.py
@@ -747,6 +747,13 @@ class SQLTests(ReusedPySparkTestCase):
except ValueError:
self.assertEqual(1, 1)
+ def test_metadata_null(self):
+ from pyspark.sql.types import StructType, StringType, StructField
+ schema = StructType([StructField("f1", StringType(), True, None),
+ StructField("f2", StringType(), True, {'a': None})])
+ rdd = self.sc.parallelize([["a", "b"], ["c", "d"]])
+ self.sqlCtx.createDataFrame(rdd, schema)
+
def test_save_and_load(self):
df = self.df
tmpPath = tempfile.mkdtemp()
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/Metadata.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/Metadata.scala
index 6ee24ee0c1..9e0f9943bc 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/Metadata.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/Metadata.scala
@@ -156,7 +156,9 @@ object Metadata {
throw new RuntimeException(s"Do not support array of type ${other.getClass}.")
}
}
- case other =>
+ case (key, JNull) =>
+ builder.putNull(key)
+ case (key, other) =>
throw new RuntimeException(s"Do not support type ${other.getClass}.")
}
builder.build()
@@ -229,6 +231,9 @@ class MetadataBuilder {
this
}
+ /** Puts a null. */
+ def putNull(key: String): this.type = put(key, null)
+
/** Puts a Long. */
def putLong(key: String, value: Long): this.type = put(key, value)