I am new to scala. I was reading one code not able to understand . Can someone please help me to understand below code ?
def intersectByKey[K: ClassTag, V: ClassTag](rdd1: RDD[(K, V)], rdd2: RDD[(K, V)]): RDD[(K, V)] = {
rdd1.cogroup(rdd2).flatMapValues{
case (Nil, _) => None
case (_, Nil) => None
case (x, y) => x++y
}
}
What does below line means ? How it will be evaluated ?
case (x, y) => x++y
Thanks
rdd1.cogroup(rdd2)
returns a value of type RDD[(K, (Iterable[V], Iterable[V]))]
.
So - in case (x, y)
both x
and y
are Iterable[V]
.
Iterable
overloads the ++
operator, with an implementation that simply means union
- returning an iterable with all of x
's values followed by all of y
's values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With