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
61be8566
Commit
61be8566
authored
12 years ago
by
Mark Hamstra
Browse files
Options
Downloads
Patches
Plain Diff
Allow distinct() to be called without parentheses when using the default number of splits.
parent
a6bb41c6
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
+3
-1
3 additions, 1 deletion
core/src/main/scala/spark/RDD.scala
core/src/test/scala/spark/RDDSuite.scala
+8
-4
8 additions, 4 deletions
core/src/test/scala/spark/RDDSuite.scala
with
11 additions
and
5 deletions
core/src/main/scala/spark/RDD.scala
+
3
−
1
View file @
61be8566
...
@@ -185,9 +185,11 @@ abstract class RDD[T: ClassManifest](@transient sc: SparkContext) extends Serial
...
@@ -185,9 +185,11 @@ abstract class RDD[T: ClassManifest](@transient sc: SparkContext) extends Serial
/**
/**
* Return a new RDD containing the distinct elements in this RDD.
* Return a new RDD containing the distinct elements in this RDD.
*/
*/
def
distinct
(
numSplits
:
Int
=
splits
.
size
)
:
RDD
[
T
]
=
def
distinct
(
numSplits
:
Int
)
:
RDD
[
T
]
=
map
(
x
=>
(
x
,
null
)).
reduceByKey
((
x
,
y
)
=>
x
,
numSplits
).
map
(
_
.
_1
)
map
(
x
=>
(
x
,
null
)).
reduceByKey
((
x
,
y
)
=>
x
,
numSplits
).
map
(
_
.
_1
)
def
distinct
()
:
RDD
[
T
]
=
distinct
(
splits
.
size
)
/**
/**
* Return a sampled subset of this RDD.
* Return a sampled subset of this RDD.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
core/src/test/scala/spark/RDDSuite.scala
+
8
−
4
View file @
61be8566
...
@@ -8,9 +8,9 @@ import spark.rdd.CoalescedRDD
...
@@ -8,9 +8,9 @@ import spark.rdd.CoalescedRDD
import
SparkContext._
import
SparkContext._
class
RDDSuite
extends
FunSuite
with
BeforeAndAfter
{
class
RDDSuite
extends
FunSuite
with
BeforeAndAfter
{
var
sc
:
SparkContext
=
_
var
sc
:
SparkContext
=
_
after
{
after
{
if
(
sc
!=
null
)
{
if
(
sc
!=
null
)
{
sc
.
stop
()
sc
.
stop
()
...
@@ -19,11 +19,15 @@ class RDDSuite extends FunSuite with BeforeAndAfter {
...
@@ -19,11 +19,15 @@ class RDDSuite extends FunSuite with BeforeAndAfter {
// To avoid Akka rebinding to the same port, since it doesn't unbind immediately on shutdown
// To avoid Akka rebinding to the same port, since it doesn't unbind immediately on shutdown
System
.
clearProperty
(
"spark.master.port"
)
System
.
clearProperty
(
"spark.master.port"
)
}
}
test
(
"basic operations"
)
{
test
(
"basic operations"
)
{
sc
=
new
SparkContext
(
"local"
,
"test"
)
sc
=
new
SparkContext
(
"local"
,
"test"
)
val
nums
=
sc
.
makeRDD
(
Array
(
1
,
2
,
3
,
4
),
2
)
val
nums
=
sc
.
makeRDD
(
Array
(
1
,
2
,
3
,
4
),
2
)
assert
(
nums
.
collect
().
toList
===
List
(
1
,
2
,
3
,
4
))
assert
(
nums
.
collect
().
toList
===
List
(
1
,
2
,
3
,
4
))
val
dups
=
sc
.
makeRDD
(
Array
(
1
,
1
,
2
,
2
,
3
,
3
,
4
,
4
),
2
)
assert
(
dups
.
distinct
.
count
===
4
)
assert
(
dups
.
distinct
().
collect
===
dups
.
distinct
.
collect
)
assert
(
dups
.
distinct
(
2
).
collect
===
dups
.
distinct
.
collect
)
assert
(
nums
.
reduce
(
_
+
_
)
===
10
)
assert
(
nums
.
reduce
(
_
+
_
)
===
10
)
assert
(
nums
.
fold
(
0
)(
_
+
_
)
===
10
)
assert
(
nums
.
fold
(
0
)(
_
+
_
)
===
10
)
assert
(
nums
.
map
(
_
.
toString
).
collect
().
toList
===
List
(
"1"
,
"2"
,
"3"
,
"4"
))
assert
(
nums
.
map
(
_
.
toString
).
collect
().
toList
===
List
(
"1"
,
"2"
,
"3"
,
"4"
))
...
@@ -121,7 +125,7 @@ class RDDSuite extends FunSuite with BeforeAndAfter {
...
@@ -121,7 +125,7 @@ class RDDSuite extends FunSuite with BeforeAndAfter {
val
zipped
=
nums
.
zip
(
nums
.
map
(
_
+
1.0
))
val
zipped
=
nums
.
zip
(
nums
.
map
(
_
+
1.0
))
assert
(
zipped
.
glom
().
map
(
_
.
toList
).
collect
().
toList
===
assert
(
zipped
.
glom
().
map
(
_
.
toList
).
collect
().
toList
===
List
(
List
((
1
,
2.0
),
(
2
,
3.0
)),
List
((
3
,
4.0
),
(
4
,
5.0
))))
List
(
List
((
1
,
2.0
),
(
2
,
3.0
)),
List
((
3
,
4.0
),
(
4
,
5.0
))))
intercept
[
IllegalArgumentException
]
{
intercept
[
IllegalArgumentException
]
{
nums
.
zip
(
sc
.
parallelize
(
1
to
4
,
1
)).
collect
()
nums
.
zip
(
sc
.
parallelize
(
1
to
4
,
1
)).
collect
()
}
}
...
...
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