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

Document the implicit resolution chain for codecs #152

Open
calvinlfer opened this issue Apr 23, 2023 · 0 comments
Open

Document the implicit resolution chain for codecs #152

calvinlfer opened this issue Apr 23, 2023 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@calvinlfer
Copy link
Member

For example:
Given the following Cassandra Row

final case class CassandraRow(a: Int, b: Long, c: OuterData)
final case class OuterData(x: String, y: String, z: InnerData)
final case class InnerData(i: Int)

We can see CassandraRow contains nested data which will be stored as a UDT value and that OuterData also contains InnerData which is also stored as a UDT value, so we have a UDT value in a Row and a UDT value within a UDT value.

How do the implicits resolve to build a CqlDecoder?

  • For a: Int -> we have a CqlPrimitiveDecoder[Int] - this gets summoned in the derivation (before going through the implicit conversion from PrimitiveDecoder -> CqlDecoder)

  • For b: Long -> we have a CqlPrimitiveDecoder[Long] - this gets summoned in the derivation (before going through the implicit conversion from PrimitiveDecoder -> CqlDecoder)

  • For c: OuterData -> this is more interesting, this ends up having a CqlPrimitiveDecoder[OuterData], but how does that get materialized?
    We get that through CqlUDTValueDecoder[OuterData]

If we step through the derivation of CqlUdtValueDecoder[OuterData], we'll find that it uses CqlPrimitiveDecoder to summon instances of String (x and y) and then you'll notice InnerData is also a UDTValue, so what ends up happening is you use CqlPrimitiveDecoder[InnerData] which ends up calling out to CqlUDTValueDecoder[InnerData] which ends up calling back out to CqlPrimitiveDecoder[Int] (the i: Int in InnerData).

You can see that CqlPrimitiveDecoder is a bridge that links all the mechanisms together
Perhaps this linking mechanism is unnecessary but this is how it currently works.

implicit call graph

@calvinlfer calvinlfer added the documentation Improvements or additions to documentation label Apr 23, 2023
@calvinlfer calvinlfer self-assigned this Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant