-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21534][SQL][PySpark] PickleException when creating dataframe from python row with empty bytearray #19085
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,16 @@ import org.apache.spark.rdd.RDD | |
|
|
||
| /** Utilities for serialization / deserialization between Python and Java, using Pickle. */ | ||
| private[spark] object SerDeUtil extends Logging { | ||
| class ByteArrayConstructor extends net.razorvine.pickle.objects.ByteArrayConstructor { | ||
| override def construct(args: Array[Object]): Object = { | ||
| // Deal with an empty byte array pickled by Python 3. | ||
| if (args.length == 0) { | ||
| Array.empty[Byte] | ||
|
||
| } else { | ||
| super.construct(args) | ||
| } | ||
| } | ||
| } | ||
| // Unpickle array.array generated by Python 2.6 | ||
| class ArrayConstructor extends net.razorvine.pickle.objects.ArrayConstructor { | ||
| // /* Description of types */ | ||
|
|
@@ -108,6 +118,10 @@ private[spark] object SerDeUtil extends Logging { | |
| synchronized{ | ||
| if (!initialized) { | ||
| Unpickler.registerConstructor("array", "array", new ArrayConstructor()) | ||
| Unpickler.registerConstructor("__builtin__", "bytearray", new ByteArrayConstructor()) | ||
| Unpickler.registerConstructor("builtins", "bytearray", new ByteArrayConstructor()) | ||
| Unpickler.registerConstructor("__builtin__", "bytes", new ByteArrayConstructor()) | ||
| Unpickler.registerConstructor("_codecs", "encode", new ByteArrayConstructor()) | ||
| initialized = true | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2480,6 +2480,11 @@ def assertCollectSuccess(typecode, value): | |
| a = array.array(t) | ||
| self.spark.createDataFrame([Row(myarray=a)]).collect() | ||
|
|
||
| # test for SPARK-21534 | ||
| def test_empty_bytearray(self): | ||
| rdd = self.spark.sql("select unhex('') as xx").rdd.map(lambda x: {"abc": x.xx}) | ||
| self.spark.createDataFrame(rdd).collect() | ||
|
||
|
|
||
| def test_bucketed_write(self): | ||
| data = [ | ||
| (1, "foo", 3.0), (2, "foo", 5.0), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. It looks quite straightforward. I checked in Python 3:
which, up to my knowledge, gives new object[0] for
args.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also checked
pickle.dumps(..., protocol=0 - 4)just in case.