How to match an RDD[ParentClass] with RDD[Subclass] in apache spark?
问题 I have to match an rdd with its types. trait Fruit case class Apple(price:Int) extends Fruit case class Mango(price:Int) extends Fruit Now a dstream of type DStream[Fruit] is coming. It is either Apple or Mango . How to perform operation based on the subclass? Something like the below (which doesn't work): dStream.foreachRDD{rdd:RDD[Fruit] => rdd match { case rdd: RDD[Apple] => //do something case rdd: RDD[Mango] => //do something case _ => println(rdd.count() + "<<<< not matched anything") }