Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala - Operation in case (x,y)=> x++y

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

like image 646
Shashi Avatar asked Feb 07 '23 12:02

Shashi


1 Answers

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.

like image 168
Tzach Zohar Avatar answered Feb 16 '23 18:02

Tzach Zohar