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
80fc8c82
Commit
80fc8c82
authored
12 years ago
by
Mark Hamstra
Browse files
Options
Downloads
Patches
Plain Diff
_With[Matei]
parent
38454c4a
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
core/src/main/scala/spark/RDD.scala
+17
-17
17 additions, 17 deletions
core/src/main/scala/spark/RDD.scala
core/src/test/scala/spark/RDDSuite.scala
+3
-3
3 additions, 3 deletions
core/src/test/scala/spark/RDDSuite.scala
with
20 additions
and
20 deletions
core/src/main/scala/spark/RDD.scala
+
17
−
17
View file @
80fc8c82
...
@@ -369,25 +369,25 @@ abstract class RDD[T: ClassManifest](
...
@@ -369,25 +369,25 @@ abstract class RDD[T: ClassManifest](
* additional parameter is produced by constructorOfA, which is called in each
* additional parameter is produced by constructorOfA, which is called in each
* partition with the index of that partition.
* partition with the index of that partition.
*/
*/
def
mapWith
[
A:
ClassManifest
,
U:
ClassManifest
](
construct
orOf
A
:
Int
=>
A
,
preservesPartitioning
:
Boolean
=
false
)
def
mapWith
[
A:
ClassManifest
,
U:
ClassManifest
](
constructA
:
Int
=>
A
,
preservesPartitioning
:
Boolean
=
false
)
(
f
:
(
A
,
T
)
=>
U
)
:
RDD
[
U
]
=
{
(
f
:
(
T
,
A
)
=>
U
)
:
RDD
[
U
]
=
{
def
iterF
(
index
:
Int
,
iter
:
Iterator
[
T
])
:
Iterator
[
U
]
=
{
def
iterF
(
index
:
Int
,
iter
:
Iterator
[
T
])
:
Iterator
[
U
]
=
{
val
a
=
construct
orOf
A
(
index
)
val
a
=
constructA
(
index
)
iter
.
map
(
t
=>
f
(
a
,
t
))
iter
.
map
(
t
=>
f
(
t
,
a
))
}
}
new
MapPartitionsWithIndexRDD
(
this
,
sc
.
clean
(
iterF
_
),
preservesPartitioning
)
new
MapPartitionsWithIndexRDD
(
this
,
sc
.
clean
(
iterF
_
),
preservesPartitioning
)
}
}
/**
/**
* FlatMaps f over this RDD, where f takes an additional parameter of type A. This
* FlatMaps f over this RDD, where f takes an additional parameter of type A. This
* additional parameter is produced by constructorOfA, which is called in each
* additional parameter is produced by constructorOfA, which is called in each
* partition with the index of that partition.
* partition with the index of that partition.
*/
*/
def
flatMapWith
[
A:
ClassManifest
,
U:
ClassManifest
](
construct
orOf
A
:
Int
=>
A
,
preservesPartitioning
:
Boolean
=
false
)
def
flatMapWith
[
A:
ClassManifest
,
U:
ClassManifest
](
constructA
:
Int
=>
A
,
preservesPartitioning
:
Boolean
=
false
)
(
f
:
(
A
,
T
)
=>
Seq
[
U
])
:
RDD
[
U
]
=
{
(
f
:
(
T
,
A
)
=>
Seq
[
U
])
:
RDD
[
U
]
=
{
def
iterF
(
index
:
Int
,
iter
:
Iterator
[
T
])
:
Iterator
[
U
]
=
{
def
iterF
(
index
:
Int
,
iter
:
Iterator
[
T
])
:
Iterator
[
U
]
=
{
val
a
=
construct
orOf
A
(
index
)
val
a
=
constructA
(
index
)
iter
.
flatMap
(
t
=>
f
(
a
,
t
))
iter
.
flatMap
(
t
=>
f
(
t
,
a
))
}
}
new
MapPartitionsWithIndexRDD
(
this
,
sc
.
clean
(
iterF
_
),
preservesPartitioning
)
new
MapPartitionsWithIndexRDD
(
this
,
sc
.
clean
(
iterF
_
),
preservesPartitioning
)
}
}
...
@@ -397,11 +397,11 @@ abstract class RDD[T: ClassManifest](
...
@@ -397,11 +397,11 @@ abstract class RDD[T: ClassManifest](
* This additional parameter is produced by constructorOfA, which is called in each
* This additional parameter is produced by constructorOfA, which is called in each
* partition with the index of that partition.
* partition with the index of that partition.
*/
*/
def
foreachWith
[
A:
ClassManifest
](
construct
orOf
A
:
Int
=>
A
)
def
foreachWith
[
A:
ClassManifest
](
constructA
:
Int
=>
A
)
(
f
:
(
A
,
T
)
=>
Unit
)
{
(
f
:
(
T
,
A
)
=>
Unit
)
{
def
iterF
(
index
:
Int
,
iter
:
Iterator
[
T
])
:
Iterator
[
T
]
=
{
def
iterF
(
index
:
Int
,
iter
:
Iterator
[
T
])
:
Iterator
[
T
]
=
{
val
a
=
construct
orOf
A
(
index
)
val
a
=
constructA
(
index
)
iter
.
map
(
t
=>
{
f
(
a
,
t
);
t
})
iter
.
map
(
t
=>
{
f
(
t
,
a
);
t
})
}
}
(
new
MapPartitionsWithIndexRDD
(
this
,
sc
.
clean
(
iterF
_
),
true
)).
foreach
(
_
=>
{})
(
new
MapPartitionsWithIndexRDD
(
this
,
sc
.
clean
(
iterF
_
),
true
)).
foreach
(
_
=>
{})
}
}
...
@@ -411,11 +411,11 @@ abstract class RDD[T: ClassManifest](
...
@@ -411,11 +411,11 @@ abstract class RDD[T: ClassManifest](
* additional parameter is produced by constructorOfA, which is called in each
* additional parameter is produced by constructorOfA, which is called in each
* partition with the index of that partition.
* partition with the index of that partition.
*/
*/
def
filterWith
[
A:
ClassManifest
](
construct
orOf
A
:
Int
=>
A
)
def
filterWith
[
A:
ClassManifest
](
constructA
:
Int
=>
A
)
(
p
:
(
A
,
T
)
=>
Boolean
)
:
RDD
[
T
]
=
{
(
p
:
(
T
,
A
)
=>
Boolean
)
:
RDD
[
T
]
=
{
def
iterF
(
index
:
Int
,
iter
:
Iterator
[
T
])
:
Iterator
[
T
]
=
{
def
iterF
(
index
:
Int
,
iter
:
Iterator
[
T
])
:
Iterator
[
T
]
=
{
val
a
=
construct
orOf
A
(
index
)
val
a
=
constructA
(
index
)
iter
.
filter
(
t
=>
p
(
a
,
t
))
iter
.
filter
(
t
=>
p
(
t
,
a
))
}
}
new
MapPartitionsWithIndexRDD
(
this
,
sc
.
clean
(
iterF
_
),
true
)
new
MapPartitionsWithIndexRDD
(
this
,
sc
.
clean
(
iterF
_
),
true
)
}
}
...
...
This diff is collapsed.
Click to expand it.
core/src/test/scala/spark/RDDSuite.scala
+
3
−
3
View file @
80fc8c82
...
@@ -185,7 +185,7 @@ class RDDSuite extends FunSuite with LocalSparkContext {
...
@@ -185,7 +185,7 @@ class RDDSuite extends FunSuite with LocalSparkContext {
val
ones
=
sc
.
makeRDD
(
Array
(
1
,
1
,
1
,
1
,
1
,
1
),
2
)
val
ones
=
sc
.
makeRDD
(
Array
(
1
,
1
,
1
,
1
,
1
,
1
),
2
)
val
randoms
=
ones
.
mapWith
(
val
randoms
=
ones
.
mapWith
(
(
index
:
Int
)
=>
new
Random
(
index
+
42
))
(
index
:
Int
)
=>
new
Random
(
index
+
42
))
{(
prng
:
Random
,
t
:
Int
)
=>
prng
.
nextDouble
*
t
}.
collect
()
{(
t
:
Int
,
prng
:
Random
)
=>
prng
.
nextDouble
*
t
}.
collect
()
val
prn42_3
=
{
val
prn42_3
=
{
val
prng42
=
new
Random
(
42
)
val
prng42
=
new
Random
(
42
)
prng42
.
nextDouble
();
prng42
.
nextDouble
();
prng42
.
nextDouble
()
prng42
.
nextDouble
();
prng42
.
nextDouble
();
prng42
.
nextDouble
()
...
@@ -204,7 +204,7 @@ class RDDSuite extends FunSuite with LocalSparkContext {
...
@@ -204,7 +204,7 @@ class RDDSuite extends FunSuite with LocalSparkContext {
val
ones
=
sc
.
makeRDD
(
Array
(
1
,
1
,
1
,
1
,
1
,
1
),
2
)
val
ones
=
sc
.
makeRDD
(
Array
(
1
,
1
,
1
,
1
,
1
,
1
),
2
)
val
randoms
=
ones
.
flatMapWith
(
val
randoms
=
ones
.
flatMapWith
(
(
index
:
Int
)
=>
new
Random
(
index
+
42
))
(
index
:
Int
)
=>
new
Random
(
index
+
42
))
{(
prng
:
Random
,
t
:
Int
)
=>
{(
t
:
Int
,
prng
:
Random
)
=>
val
random
=
prng
.
nextDouble
()
val
random
=
prng
.
nextDouble
()
Seq
(
random
*
t
,
random
*
t
*
10
)}.
Seq
(
random
*
t
,
random
*
t
*
10
)}.
collect
()
collect
()
...
@@ -226,7 +226,7 @@ class RDDSuite extends FunSuite with LocalSparkContext {
...
@@ -226,7 +226,7 @@ class RDDSuite extends FunSuite with LocalSparkContext {
val
ints
=
sc
.
makeRDD
(
Array
(
1
,
2
,
3
,
4
,
5
,
6
),
2
)
val
ints
=
sc
.
makeRDD
(
Array
(
1
,
2
,
3
,
4
,
5
,
6
),
2
)
val
sample
=
ints
.
filterWith
(
val
sample
=
ints
.
filterWith
(
(
index
:
Int
)
=>
new
Random
(
index
+
42
))
(
index
:
Int
)
=>
new
Random
(
index
+
42
))
{(
prng
:
Random
,
t
:
Int
)
=>
prng
.
nextInt
(
3
)
==
0
}.
{(
t
:
Int
,
prng
:
Random
)
=>
prng
.
nextInt
(
3
)
==
0
}.
collect
()
collect
()
val
checkSample
=
{
val
checkSample
=
{
val
prng42
=
new
Random
(
42
)
val
prng42
=
new
Random
(
42
)
...
...
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