我有不同类型的特征管道对象,我想将这些对象存储在一个结构中,以便进一步访问。管道顺序动态更改。
trait Pipe[In, Out] {
def apply(rdd: RDD[In]): RDD[Out]
def |[Final](next: Pipe[Out, Final]): Pipe[In, Final] = {
// Close over outer object
val self = this
new Pipe[In, Final] {
// Run first transform, pass results to next
def apply(rdd: RDD[In]) = next(self(rdd))
}
}
}
val timestampConverter = new Pipe[String, String]
val summaryBuilder = new Pipe[String, String]
val rddSeperator = new Pipe[String, (String, ArrayBuffer[Double])]
val rddSorter = new Pipe[(String, Double), String]
val pipeline = timestampConverter | summaryBuilder | rddSeperator | rddSorter
答案 0 :(得分:0)
import shapeless.hlist.ops._
import shapless.::
trait Pipe[In, HL <: HList] { self =>
def apply(rdd: RDD[In]): RDD[Out]
def |[Final](
next: Pipe[Out, Final :: HL]
): Pipe[In, Final :: HL] = {
new Pipe[In, Final :: HL] {
// Run first transform, pass results to next
def apply(rdd: RDD[In]) = next(self(rdd))
}
}
}
听起来你可以用一个简单的异类列表。由于序列化,我不确定它与Spark有多好,但值得一试。然后,您可以反转HL
以按输入顺序获取参数。
不需要self
引用,这不是JavaScript。