-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AnyVal blows up TypedEncoder / Injection #161
Comments
Good catch! Ok, can you remove the injection? Any case class should be straightforwardly encoded without Injection. Also, what version are you on? |
The following works just fine for me: import frameless._
import frameless.syntax._
case class CustomerId(value: Long) //extends AnyVal
object CustomerId {
implicit val _injection: Injection[CustomerId, Long] =
Injection[CustomerId, Long](_.value,CustomerId.apply)
implicit val _encoder: TypedEncoder[CustomerId] =
frameless.TypedEncoder.usingInjection[CustomerId, Long]
}
TypedDataset.create(Seq(CustomerId(2))).show().run Can you provide a minimal example that showcases this issue? |
I've reproduced this issue with following code: case class CustomerId(value: Long) extends AnyVal
object CustomerId {
implicit def injection: Injection[CustomerId, Long] =
Injection(_.value, CustomerId(_))
implicit def encoder: TypedEncoder[CustomerId] =
TypedEncoder.usingInjection[CustomerId, Long]
implicit def arbitrary: Arbitrary[CustomerId] = Arbitrary {
Arbitrary.arbLong.arbitrary.map(CustomerId(_))
}
}
case class Customer(id: CustomerId, name: String)
object Customer {
implicit def arbitrary: Arbitrary[Customer] = Arbitrary {
for {
id <- Arbitrary.arbitrary[CustomerId]
name <- Gen.alphaNumStr
} yield Customer(id, name)
}
} There are 3 related issues:
case class Customer(id: CustomerId) becomes class Customer {
long id() { ... }
} But we generate code assuming The other way is to provide specialize encoder for One of workarounds is to manually declare encoders: implicit def encoder: TypedEncoder[CustomerId] = new TypedEncoder[CustomerId] {
def nullable: Boolean = false
def sourceDataType: DataType = LongType
def targetDataType: DataType = LongType
def constructorFor(path: Expression): Expression = path
def extractorFor(path: Expression): Expression = path
} But it would work only if |
Closed by #546 |
Im using CustomerId in a larger Product type, if I decide to uncomment the //extends AnyVal I get a lovely explosion in a catalyst.codegen step:
(P.S - It seems odd that i have to explicitly add the field _encoder -- for some reason, the implicit def for usingInjection isnt being implicitly found - but im not ruling out me forgetting something basic about implicits)
The text was updated successfully, but these errors were encountered: