Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-7565][SQL] Also consider java string in writePrimitive for StringType #6084

Closed
wants to merge 2 commits into from
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
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"}}'])
schema = StructType([StructField("obj", MapType(StringType(), StringType()), True)])
df = self.sqlCtx.jsonRDD(rdd, schema)
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