Scala Spark Software structure blueprint

Viewed 33

I'm kinda a newbie to Scala and I need help with my Scala Spark batch jobs software structure.

I've tought of using something similar to Chain of responsability pattern and came up with this :

trait Step{
  def process(ds: Dataset[_]): Dataset[_]
}

trait InitStep{
   def process(): Dataset[_]
}

class Pipeline(init: InitStep, steps: Step*){

  def executePipeline: Dataset[_] = steps.foldLeft(init.process()){
      case (dfAcc, step) => {
        // Log start of step <step name>
        dfAcc.transform(step.process)
        // Log end of step <step name>
      }
  }

}

Basically, each batch job should have one InitStep, which takes no parameters and returns a Dataset. It also has 0 or more steps, these steps takes the previous step Dataset as argument, and returns another Dataset.

One major weakness of my model is that some of my Steps might share common transformed (or not) datasets. For example, in step n I could generate a Dataset, cache it, and then use the cached Dataset in steps n+1 and n+2 and the current blueprint won't allow me to do this.

Also, I'm not sure that's the most scala-ish way to do it.

Can you please tell me how I can improve my model or suggest me something better ?

Thanks,

0 Answers
Related