Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-4818][Core] Add 'iterator' to reduce memory consumed by join #3671

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions core/src/main/scala/org/apache/spark/rdd/PairRDDFunctions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class PairRDDFunctions[K, V](self: RDD[(K, V)])
*/
def join[W](other: RDD[(K, W)], partitioner: Partitioner): RDD[(K, (V, W))] = {
this.cogroup(other, partitioner).flatMapValues( pair =>
for (v <- pair._1; w <- pair._2) yield (v, w)
for (v <- pair._1.iterator; w <- pair._2.iterator) yield (v, w)
)
}

Expand All @@ -493,9 +493,9 @@ class PairRDDFunctions[K, V](self: RDD[(K, V)])
def leftOuterJoin[W](other: RDD[(K, W)], partitioner: Partitioner): RDD[(K, (V, Option[W]))] = {
this.cogroup(other, partitioner).flatMapValues { pair =>
if (pair._2.isEmpty) {
pair._1.map(v => (v, None))
pair._1.iterator.map(v => (v, None): (V, Option[W]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, are these types required? or can it be limited to just changing None to None: Option[W]?
Not that it hurts to spell out the types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None to None: Option[W]

Have tried. But not work.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zsxwing First of all thanks for the patch! What kind of error are you getting without these explicit types? Compile time or runtime? I don't get any compile error/warning without these types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. My IDE had some problem. After I rebuilt the project, the errors gone.

} else {
for (v <- pair._1; w <- pair._2) yield (v, Some(w))
for (v <- pair._1.iterator; w <- pair._2.iterator) yield (v, Some(w))
}
}
}
Expand All @@ -510,9 +510,9 @@ class PairRDDFunctions[K, V](self: RDD[(K, V)])
: RDD[(K, (Option[V], W))] = {
this.cogroup(other, partitioner).flatMapValues { pair =>
if (pair._1.isEmpty) {
pair._2.map(w => (None, w))
pair._2.iterator.map(w => (None, w): (Option[V], W))
} else {
for (v <- pair._1; w <- pair._2) yield (Some(v), w)
for (v <- pair._1.iterator; w <- pair._2.iterator) yield (Some(v), w)
}
}
}
Expand All @@ -528,9 +528,9 @@ class PairRDDFunctions[K, V](self: RDD[(K, V)])
def fullOuterJoin[W](other: RDD[(K, W)], partitioner: Partitioner)
: RDD[(K, (Option[V], Option[W]))] = {
this.cogroup(other, partitioner).flatMapValues {
case (vs, Seq()) => vs.map(v => (Some(v), None))
case (Seq(), ws) => ws.map(w => (None, Some(w)))
case (vs, ws) => for (v <- vs; w <- ws) yield (Some(v), Some(w))
case (vs, Seq()) => vs.iterator.map(v => (Some(v), None): (Option[V], Option[W]))
case (Seq(), ws) => ws.iterator.map(w => (None, Some(w)): (Option[V], Option[W]))
case (vs, ws) => for (v <- vs.iterator; w <- ws.iterator) yield (Some(v), Some(w))
}
}

Expand Down