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
65e84060
Commit
65e84060
authored
12 years ago
by
Josh Rosen
Browse files
Options
Downloads
Patches
Plain Diff
Implement fold() in Python API.
parent
f3b852ce
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyspark/pyspark/rdd.py
+19
-1
19 additions, 1 deletion
pyspark/pyspark/rdd.py
with
19 additions
and
1 deletion
pyspark/pyspark/rdd.py
+
19
−
1
View file @
65e84060
...
@@ -141,7 +141,25 @@ class RDD(object):
...
@@ -141,7 +141,25 @@ class RDD(object):
vals
=
PipelinedRDD
(
self
,
func
).
collect
()
vals
=
PipelinedRDD
(
self
,
func
).
collect
()
return
reduce
(
f
,
vals
)
return
reduce
(
f
,
vals
)
# TODO: fold
def
fold
(
self
,
zeroValue
,
op
):
"""
Aggregate the elements of each partition, and then the results for all
the partitions, using a given associative function and a neutral
"
zero
value.
"
The function op(t1, t2) is allowed to modify t1 and return it
as its result value to avoid object allocation; however, it should not
modify t2.
>>>
from
operator
import
add
>>>
sc
.
parallelize
([
1
,
2
,
3
,
4
,
5
]).
fold
(
0
,
add
)
15
"""
def
func
(
iterator
):
acc
=
zeroValue
for
obj
in
iterator
:
acc
=
op
(
obj
,
acc
)
yield
acc
vals
=
PipelinedRDD
(
self
,
func
).
collect
()
return
reduce
(
op
,
vals
,
zeroValue
)
# TODO: aggregate
# TODO: aggregate
...
...
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