boilerplate free projection of case class to change data type of enum

298 Views Asked by At

I have an Enumeratum enum and need to load it into a spark data frame. Obviously, this fails due to a missing encoder.

import enumeratum._
sealed trait Foo extends EnumEntry

object Foo extends Enum[Foo] {

  val values = findValues

  case object Baz extends Foo
  case object Bar extends Foo
}
case class FooBar(a:Int, lotOfOthterFields:String, xxxx:Seq[Foo])
Seq(FooBar(1, "one", Foo.Baz), FooBar(2, "two", Foo.Bar)).toDF

Fails with No Encoder found for type Foo. How can I project the case class (without boilerplate) to:

  • either have it work fine in spark (I do not) want to have binary kryo output
  • or convert it to a string via Foo.Baz.entryName(but without boile of defining a similar class) something along the lines of Seq(FooBar(1, "one", Foo.Baz), FooBar(2, "two", Foo.Bar)).map(allValluesButxxxx, xxxx.entryName)
0

There are 0 best solutions below