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

Nested Query with Multi-Element Tuple Crashes #1580

Closed
deusaquilus opened this issue Aug 23, 2019 · 1 comment · Fixed by #1597
Closed

Nested Query with Multi-Element Tuple Crashes #1580

deusaquilus opened this issue Aug 23, 2019 · 1 comment · Fixed by #1597

Comments

@deusaquilus
Copy link
Collaborator

deusaquilus commented Aug 23, 2019

Version: (e.g. 3.4.2-SNAPSHOT)
Module: (e.g. quill-sql)
Database: (e.g. ALL)

Expected behavior

Should be able to use the result of a join in a nested tuple. This does not work however:

val ctx = new SqlMirrorContext(PostgresDialect, Literal)
import ctx._

case class Person(id: Int, name: String)
case class Address(ownerFk: Int, street: String)

val joined = quote {
  query[Person].join(query[Person]).on((a, b) => a.name == b.name)
}
val q = quote {
  joined.map {
    p => (p, infix"foobar".as[Int])
  }.filter(_._1._1.id == 1)
}
run(q)

Actual behavior

This causes a compile-time exception:

cmd2.sc:15: exception during macro expansion: 
java.lang.IllegalStateException: The monad composition can't be expressed using applicative joins. Faulty expression: '(a, b)'. Free variables: 'List(a, b)'.
	at io.getquill.util.Messages$.fail(Messages.scala:21)
	at io.getquill.context.sql.idiom.SqlIdiom$$anonfun$3.apply(SqlIdiom.scala:43)
	at io.getquill.context.sql.idiom.SqlIdiom$$anonfun$3.apply(SqlIdiom.scala:43)
	at scala.Option.map(Option.scala:146)

Workaround

Decompose the joined entity and put it into the tuple so they are not nested:

  val ctx = new SqlMirrorContext(PostgresDialect, Literal)
  import ctx._
  
  case class Person(id: Int, name: String)
  case class Address(ownerFk: Int, street: String)
  
  val joined = quote {
    query[Person].join(query[Person]).on((a, b) => a.name == b.name)
  }
  val q = quote {
    joined.map {
      case (one, two) => (one, two, infix"foobar".as[Int])
    }.filter(_._1.id == 1)
  }
  run(q)

@getquill/maintainers

@deusaquilus
Copy link
Collaborator Author

Fixed via #1597.

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

Successfully merging a pull request may close this issue.

1 participant