doric
doric copied to clipboard
Field access for custom product types
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.