zio / zio-quill

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

Joining a query with inner join + groupBy results in error #1109

Open mosyp opened 6 years ago

mosyp commented 6 years ago

Module: quill-sql

Failing - https://scastie.scala-lang.org/mentegy/ZLficzsLRBqdPkWDE6Sc8Q Working (with a workaround) - https://scastie.scala-lang.org/mentegy/p2lpqYJlRsCV68PqxhXAiQ

val q4 = quote {
  query[Teams]
  .join(q3)
  .on(...)
  .groupBy {
    case (teams, inner) => teams.id
  }
  .map {
    case (id, q) => Output(id, q.size)
  }
}

// this fails
val q5 = quote {
  query[Teams]
  .join(q4)
  .on { case (teams, inner) => teams.id == inner.teamId }  
}

Expected behavior

Produce a correct sql

Actual behavior

exception during macro expansion: 
java.lang.IllegalStateException: A `groupBy` clause must be followed by `map`.
    at io.getquill.util.Messages$.fail(Messages.scala:15)
    at io.getquill.context.sql.SqlQuery$.flatten(SqlQuery.scala:143)
    at io.getquill.context.sql.SqlQuery$.flatten(SqlQuery.scala:83)
    at io.getquill.context.sql.SqlQuery$.apply(SqlQuery.scala:76)

Workaround

use implicit join syntax


val q5 = quote {
  for {
    team <- query[Teams]
    inner <- q4
    if team.id == inner.teamId
  } yield (team, inner)
}

@getquill/maintainers

jukkagrao commented 6 years ago

Perhaps it's related to https://github.com/getquill/quill/issues/63

Ellzord commented 1 year ago

Still happening in quill-jdbc-zio 4.6.1