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
c75ae362
Commit
c75ae362
authored
12 years ago
by
Josh Rosen
Browse files
Options
Downloads
Patches
Plain Diff
Make AccumulatorParam an abstract base class.
parent
7d3e359f
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/accumulators.py
+26
-3
26 additions, 3 deletions
python/pyspark/accumulators.py
python/pyspark/context.py
+5
-10
5 additions, 10 deletions
python/pyspark/context.py
with
31 additions
and
13 deletions
python/pyspark/accumulators.py
+
26
−
3
View file @
c75ae362
...
...
@@ -61,6 +61,7 @@ Traceback (most recent call last):
Exception
:
...
"""
from
abc
import
ABCMeta
,
abstractmethod
import
struct
import
SocketServer
import
threading
...
...
@@ -90,8 +91,7 @@ class Accumulator(object):
While C{SparkContext} supports accumulators for primitive data types like C{int} and
C{float}, users can also define accumulators for custom types by providing a custom
C{AccumulatorParam} object with a C{zero} and C{addInPlace} method. Refer to the doctest
of this module for an example.
L{AccumulatorParam} object. Refer to the doctest of this module for an example.
"""
def
__init__
(
self
,
aid
,
value
,
accum_param
):
...
...
@@ -134,7 +134,30 @@ class Accumulator(object):
return
"
Accumulator<id=%i, value=%s>
"
%
(
self
.
aid
,
self
.
_value
)
class
AddingAccumulatorParam
(
object
):
class
AccumulatorParam
(
object
):
"""
Helper object that defines how to accumulate values of a given type.
"""
__metaclass__
=
ABCMeta
@abstractmethod
def
zero
(
self
,
value
):
"""
Provide a
"
zero value
"
for the type, compatible in dimensions with the
provided C{value} (e.g., a zero vector)
"""
return
@abstractmethod
def
addInPlace
(
self
,
value1
,
value2
):
"""
Add two values of the accumulator
'
s data type, returning a new value;
for efficiency, can also update C{value1} in place and return it.
"""
return
class
AddingAccumulatorParam
(
AccumulatorParam
):
"""
An AccumulatorParam that uses the + operators to add values. Designed for simple types
such as integers, floats, and lists. Requires the zero value for the underlying type
...
...
This diff is collapsed.
Click to expand it.
python/pyspark/context.py
+
5
−
10
View file @
c75ae362
...
...
@@ -148,16 +148,11 @@ class SparkContext(object):
def
accumulator
(
self
,
value
,
accum_param
=
None
):
"""
Create an C{Accumulator} with the given initial value, using a given
AccumulatorParam helper object to define how to add values of the data
type if provided. Default AccumulatorParams are used for integers and
floating-point numbers if you do not provide one. For other types, the
AccumulatorParam must implement two methods:
- C{zero(value)}: provide a
"
zero value
"
for the type, compatible in
dimensions with the provided C{value} (e.g., a zero vector).
- C{addInPlace(val1, val2)}: add two values of the accumulator
'
s data
type, returning a new value; for efficiency, can also update C{val1}
in place and return it.
Create an L{Accumulator} with the given initial value, using a given
L{AccumulatorParam} helper object to define how to add values of the
data type if provided. Default AccumulatorParams are used for integers
and floating-point numbers if you do not provide one. For other types,
a custom AccumulatorParam can be used.
"""
if
accum_param
==
None
:
if
isinstance
(
value
,
int
):
...
...
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