doric icon indicating copy to clipboard operation
doric copied to clipboard

Field access for custom product types

Open jserranohidalgo opened this issue 2 years ago • 0 comments

For instance, given the following custom product type:

case class User(name: String, age: Int)
object User {
  implicit val userst: SparkType.Custom[User, String] =
    SparkType[String].customType[User](x => {
      val name :: age :: Nil = x.split("#").toList
      User(name, age.toInt)
    })

  implicit val userlst: LiteralSparkType.Custom[User, String] =
    LiteralSparkType[String].customType[User](x => s"${x.name}#${x.age}")
}

we would like to access fields of users as follows:

col[User]("user").field("name"): DoricColumn[String]
col[User]("user").field("age"): DoricColumn[Int]

That is, even if the User product type is internally represented as a String, doric must offer programmers the API of product types for manipulating User columns.

jserranohidalgo avatar Jul 14 '22 14:07 jserranohidalgo