Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,13 @@ def test_struct_type(self):
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -229,6 +231,9 @@ class MetadataBuilder {
this
}

/** Puts a null. */
def putNull(key: String): this.type = put(key, null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like not worth adding a method since it is just used once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is created for code organization and clarity purpose. This way it can be easily reused in the future.


/** Puts a Long. */
def putLong(key: String, value: Long): this.type = put(key, value)

Expand Down