Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
3787f514
Commit
3787f514
authored
11 years ago
by
Josh Rosen
Browse files
Options
Downloads
Patches
Plain Diff
Fix UnicodeEncodeError in PySpark saveAsTextFile().
Fixes SPARK-970.
parent
743a31a7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/pyspark/rdd.py
+4
-1
4 additions, 1 deletion
python/pyspark/rdd.py
python/pyspark/tests.py
+15
-0
15 additions, 0 deletions
python/pyspark/tests.py
with
19 additions
and
1 deletion
python/pyspark/rdd.py
+
4
−
1
View file @
3787f514
...
...
@@ -605,7 +605,10 @@ class RDD(object):
'
0
\\
n1
\\
n2
\\
n3
\\
n4
\\
n5
\\
n6
\\
n7
\\
n8
\\
n9
\\
n
'
"""
def
func
(
split
,
iterator
):
return
(
str
(
x
).
encode
(
"
utf-8
"
)
for
x
in
iterator
)
for
x
in
iterator
:
if
not
isinstance
(
x
,
basestring
):
x
=
unicode
(
x
)
yield
x
.
encode
(
"
utf-8
"
)
keyed
=
PipelinedRDD
(
self
,
func
)
keyed
.
_bypass_serializer
=
True
keyed
.
_jrdd
.
map
(
self
.
ctx
.
_jvm
.
BytesToString
()).
saveAsTextFile
(
path
)
...
...
This diff is collapsed.
Click to expand it.
python/pyspark/tests.py
+
15
−
0
View file @
3787f514
...
...
@@ -19,6 +19,8 @@
Unit tests for PySpark; additional tests are implemented as doctests in
individual modules.
"""
from
fileinput
import
input
from
glob
import
glob
import
os
import
shutil
import
sys
...
...
@@ -138,6 +140,19 @@ class TestAddFile(PySparkTestCase):
self
.
assertEqual
(
"
Hello World from inside a package!
"
,
UserClass
().
hello
())
class
TestRDDFunctions
(
PySparkTestCase
):
def
test_save_as_textfile_with_unicode
(
self
):
# Regression test for SPARK-970
x
=
u
"
\u00A1
Hola, mundo!
"
data
=
self
.
sc
.
parallelize
([
x
])
tempFile
=
NamedTemporaryFile
(
delete
=
True
)
tempFile
.
close
()
data
.
saveAsTextFile
(
tempFile
.
name
)
raw_contents
=
''
.
join
(
input
(
glob
(
tempFile
.
name
+
"
/part-0000*
"
)))
self
.
assertEqual
(
x
,
unicode
(
raw_contents
.
strip
(),
"
utf-8
"
))
class
TestIO
(
PySparkTestCase
):
def
test_stdout_redirection
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment