I am trying to create a customRDD in Java.
RDD converts RDD[(K,V)]
to PairRDDFunctions[K,V]
using Scala implicit function rddToPairRDDFunctions()
defined in object RDD
.
I am trying to do the same with my CustomJavaRDD
which extends CustomRDD
which extends RDD
.
Now it should call implicit function rddToCustomJavaRDDFunctions()
whenever it encounters CustomJavaRDD[(K,V)]
, but for some reason it still goes to rddToPairRDDFunctions()
.
What am I doing wrong?
RDD.scala
class RDD[T]
object RDD {
implicit def rddToPairRDDFunctions[K, V](rdd: RDD[(K, V)])
(implicit kt: ClassTag[K], vt: ClassTag[V], ord: Ordering[K] = null):
PairRDDFunctions[K, V] = {
new PairRDDFunctions(rdd)
}
}
CustomRDD.scala
abstract class CustomRDD[T] extends RDD[T]
object CustomRDD {
implicit def rddToCustomJavaRDDFunctions[K,V](rdd: CustomJavaRDD[(K,V)]):
PairCustomJavaRDDFunction[K,V] = {
new PairCustomJavaRDDFunctions[K,V](rdd)
}
}
PairCustomJavaRDDFunctions.scala
class PairCustomJavaRDDFunctions[K: ClassTag, V: ClassTag](self: CustomRDD[(K, V)])
(implicit ord: Ordering[K] = null) {
def collectAsMap() = ???
}
There is no error; the program compiles successfully,
but let's say I have data: RDD
which is an instance of CustomJavaRDD
.
data.collectAsMap()
At the runtime it converts data
into PairRDDFunctions
; i.e. it makes implicit call to rddToPairRDDFunctions
defined in RDD.scala.
But it should make call to rddToCustomJavaRDDFunctions
defined in CustomRDD.scala and convert it into PairCustomJavaRDDFunctions
.