Skip to content

Commit

Permalink
Also consider java string in writePrimitive for StringType.
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed May 12, 2015
1 parent 640f63b commit cc3ec61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,15 @@ def test_save_and_load(self):
self.assertTrue(sorted(df.collect()) == sorted(actual.collect()))
self.sqlCtx.sql("SET spark.sql.sources.default=" + defaultDataSourceName)

tmpPath2 = tempfile.mkdtemp()
shutil.rmtree(tmpPath2)
rdd = self.sc.parallelize(['{"obj": {"a": "hello"}}', '{"obj": {"b": "world"}}'])
df = self.sqlCtx.jsonRDD(rdd,
StructType([StructField("obj", MapType(StringType(), StringType()), True)]))
df.save(tmpPath2, 'org.apache.spark.sql.parquet', mode='overwrite')

shutil.rmtree(tmpPath)
shutil.rmtree(tmpPath2)

def test_help_command(self):
# Regression test for SPARK-5464
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ private[parquet] class RowWriteSupport extends WriteSupport[Row] with Logging {
private[parquet] def writePrimitive(schema: DataType, value: Any): Unit = {
if (value != null) {
schema match {
case StringType => writer.addBinary(
case StringType if value.isInstanceOf[String] => writer.addBinary(
Binary.fromByteArray(UTF8String(value.asInstanceOf[String]).getBytes))
case StringType if value.isInstanceOf[UTF8String] => writer.addBinary(
Binary.fromByteArray(value.asInstanceOf[UTF8String].getBytes))
case BinaryType => writer.addBinary(
Binary.fromByteArray(value.asInstanceOf[Array[Byte]]))
Expand Down

0 comments on commit cc3ec61

Please sign in to comment.