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
94ba95bc
Commit
94ba95bc
authored
14 years ago
by
Matei Zaharia
Browse files
Options
Downloads
Patches
Plain Diff
Added flatMapValues
parent
d840fa8d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/scala/spark/RDD.scala
+23
-4
23 additions, 4 deletions
core/src/main/scala/spark/RDD.scala
with
23 additions
and
4 deletions
core/src/main/scala/spark/RDD.scala
+
23
−
4
View file @
94ba95bc
...
...
@@ -251,12 +251,16 @@ extends RDD[Array[T]](prev.context) {
def
collectAsMap
()
:
Map
[
K
,
V
]
=
HashMap
(
self
.
collect
()
:
_
*
)
def
mapValues
[
U
](
f
:
V
=>
U
)
:
RDD
[(
K
,
U
)]
=
{
def
mapValues
[
U
](
f
:
V
=>
U
)
:
RDD
[(
K
,
U
)]
=
{
val
cleanF
=
self
.
context
.
clean
(
f
)
new
MappedValuesRDD
(
self
,
cleanF
)
}
def
flatMapValues
[
U
](
f
:
V
=>
Traversable
[
U
])
:
RDD
[(
K
,
U
)]
=
{
val
cleanF
=
self
.
context
.
clean
(
f
)
new
FlatMappedValuesRDD
(
self
,
cleanF
)
}
def
groupWith
[
W
](
other
:
RDD
[(
K
,
W
)])
:
RDD
[(
K
,
(
Seq
[
V
]
,
Seq
[
W
]))]
=
{
val
part
=
self
.
partitioner
match
{
case
Some
(
p
)
=>
p
...
...
@@ -291,6 +295,21 @@ extends RDD[(K, U)](prev.context) {
override
def
splits
=
prev
.
splits
override
def
preferredLocations
(
split
:
Split
)
=
prev
.
preferredLocations
(
split
)
override
val
dependencies
=
List
(
new
OneToOneDependency
(
prev
))
override
def
compute
(
split
:
Split
)
=
prev
.
iterator
(
split
).
map
{
case
(
k
,
v
)
=>
(
k
,
f
(
v
))}
override
val
partitioner
=
prev
.
partitioner
}
\ No newline at end of file
override
def
compute
(
split
:
Split
)
=
prev
.
iterator
(
split
).
map
{
case
(
k
,
v
)
=>
(
k
,
f
(
v
))}
}
class
FlatMappedValuesRDD
[
K
,
V
,
U
](
prev
:
RDD
[(
K
,
V
)],
f
:
V
=>
Traversable
[
U
])
extends
RDD
[(
K
,
U
)](
prev
.
context
)
{
override
def
splits
=
prev
.
splits
override
def
preferredLocations
(
split
:
Split
)
=
prev
.
preferredLocations
(
split
)
override
val
dependencies
=
List
(
new
OneToOneDependency
(
prev
))
override
val
partitioner
=
prev
.
partitioner
override
def
compute
(
split
:
Split
)
=
{
prev
.
iterator
(
split
).
toStream
.
flatMap
{
case
(
k
,
v
)
=>
f
(
v
).
map
(
x
=>
(
k
,
x
))
}.
iterator
}
}
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