I'm working in Spark 3.1 with Scala 2.12.10.
I'd like to create a collection (Seq, whatever) of case classes that have implemented a common trait, so I can execute some generic dataset code on the collection members without having to type each incantation separately. I think I can get the erased type via TypeTag, but I'm unable to define the collection in the first place!
Given these types:
trait HasID { val id: String }
case class Customer(id: String, name: String) extends HasID
case class Product(id: String, desc: Int) extends HasID
case class Sale(id: String, value: Float) extends HasID
class Appender[T <: HasID : Encoder] { ... } // dataset methods
I can call the code:
new Appender[Customer]() ...
new Appender[Product]() ...
new Appender[Sale]() ...
But what I want is to put the classes in a collection and loop through it:
Seq[HasID](Customer, Product, Sale).foreach(c =>
// get type C of c somehow
new Appender[C]() ...
)