zio / zio-quill

Compile-time Language Integrated Queries for Scala
https://zio.dev/zio-quill
Apache License 2.0
2.15k stars 348 forks source link

Embedded Scala case classes are not translated to CQL queries #3125

Open tashoyan opened 4 weeks ago

tashoyan commented 4 weeks ago

This template isn't a strict requirement to open issues, but please try to provide as much information as possible.

Version: ZIO Quill 4.8.4 Module: quill-cassandra Database: Cassandra

Expected behavior

As described in the chapter Embedded case classes:

Scala classes to describe Cassandra DB entities:

final case class Contact(phone: String, address: String)
final case class Person(id: Int, name: String, contact: Contact)

DAO to retrieve Persons from Cassandra DB:

class PersonDao(implicit ctx: CassandraAsyncContext[SnakeCase]) {
  import ctx._

  def retrievePersons: Future[List[Person]] = {
    ctx.run(query[Person])
  }

}

Expected CQL query:

SELECT x.id, x.name, x.phone, x.address FROM Person x

Actual behavior

Actual CQL query generated:

SELECT id, name, contact FROM person

The query contains a wrong column contact. Instead it should contain attributes of the embedded case class Contact: phone and address.

I tried to add extends Embedded but this doesn't help.

Steps to reproduce the behavior

Take the example documented in Embedded case classes and try to compile and run it. When compiling, the compiler prints the generated query on stdio.

Workaround

Don't use embedded case classes for database queries, use additional flat case classes instead. This is quite inconvenient and requires to write additional transformations between the two formats.