Skip to content
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

Deriving logic prefers derived case class mapper over custom provided #322

Open
alosich opened this issue Dec 30, 2021 · 0 comments
Open

Comments

@alosich
Copy link

alosich commented Dec 30, 2021

In case if case class contains case class, inner case class correctly interpreted as RECORD however, if custom mapper provided (as in example in documentation), schema generator treats it as field of custom type, but ToMappable derived in still treats it as RECORD.

This test (as per documentation) succeeds:

import shapeless.datatype.bigquery._
import java.net.URI

implicit val uriBigQueryType = BigQueryType.at[URI]("STRING")(v => URI.create(v.toString), _.toString)

case class Page(uri: URI, rank: Int)

val t = BigQueryType[Page]
val r = t.toTableRow(Page(URI.create("www.google.com"), 42))

// this is as expected
r.get("uri") ==== "www.google.com"

while this fails:

import shapeless.datatype.bigquery._

case class Yuri(ss: String)
implicit val uriBigQueryType = BigQueryType.at[Yuri]("STRING")(v => new Yuri(v.toString), _.ss)

case class Page(uri: Yuri, rank: Int)

val t = BigQueryType[Page]
val r = t.toTableRow(Page(new Yuri("www.google.com"), 42))

// this FAILS, instead of string, it contains linked hash map.
r.get("uri") ==== "www.google.com"

Note that the only difference here is that instead of system non-case URI class, custom case class Yuri is used (and if I switch it from being case class to normal class, the problem is gone).

I think that reason is that ToMappable.hconsToMappable0 (which constructs basing on internal structure of case class) implicit has bigger priority than ToMappable.hconsToMappable1 (which uses externally provided mapper).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant