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 Queries with Embedded in Ad-Hoc Case Class Crashes #1598

Closed
deusaquilus opened this issue Sep 8, 2019 · 1 comment
Closed

Nested Queries with Embedded in Ad-Hoc Case Class Crashes #1598

deusaquilus opened this issue Sep 8, 2019 · 1 comment

Comments

@deusaquilus
Copy link
Collaborator

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

Expected behavior

The following query should work:

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

case class TestEntity(s: String, i: Int, l: Long, o: Option[Int]) extends Embedded
case class Dual(ta: TestEntity, tb: TestEntity)

val qr1 = quote {
  query[TestEntity]
}

val q = quote {
  qr1.join(qr1).on((a, b) => a.i == b.i).nested.map(both => both match { case (a, b) => Dual(a, b) }).nested
}

println(run(q).string)

Actual behavior

The following exception happens:

cmd7.sc:1: exception during macro expansion: 
java.lang.IndexOutOfBoundsException: 1
	at scala.collection.LinearSeqOptimized$class.apply(LinearSeqOptimized.scala:65)
	at scala.collection.immutable.List.apply(List.scala:84)
	at io.getquill.context.sql.norm.ExpandNestedQueries$.io$getquill$context$sql$norm$ExpandNestedQueries$$expandReference$1(ExpandNestedQueries.scala:90)
	at io.getquill.context.sql.norm.ExpandNestedQueries$.io$getquill$context$sql$norm$ExpandNestedQueries$$expandReference$1(ExpandNestedQueries.scala:80)
	at io.getquill.context.sql.norm.ExpandNestedQueries$$anonfun$expandSelect$1.apply(ExpandNestedQueries.scala:108)
	at io.getquill.context.sql.norm.ExpandNestedQueries$$anonfun$expandSelect$1.apply(ExpandNestedQueries.scala:108)
	at scala.collection.immutable.List.map(List.scala:288)
	at io.getquill.context.sql.norm.ExpandNestedQueries$.expandSelect(ExpandNestedQueries.scala:108)
	at io.getquill.context.sql.norm.ExpandNestedQueries$.apply(ExpandNestedQueries.scala:30)
	at io.getquill.context.sql.norm.ExpandNestedQueries$.io$getquill$context$sql$norm$ExpandNestedQueries$$expandContext(ExpandNestedQueries.scala:48)
	at io.getquill.context.sql.norm.ExpandNestedQueries$$anonfun$3.apply(ExpandNestedQueries.scala:41)
	at io.getquill.context.sql.norm.ExpandNestedQueries$$anonfun$3.apply(ExpandNestedQueries.scala:41)
	at scala.collection.immutable.List.map(List.scala:284)
	at io.getquill.context.sql.norm.ExpandNestedQueries$.expandNested(ExpandNestedQueries.scala:41)
	at io.getquill.context.sql.norm.ExpandNestedQueries$.apply(ExpandNestedQueries.scala:30)
	at io.getquill.context.sql.norm.ExpandNestedQueries$.apply(ExpandNestedQueries.scala:23)
	at io.getquill.context.sql.idiom.SqlIdiom$class.translate(SqlIdiom.scala:44)
	at io.getquill.PostgresDialect$.translate(PostgresDialect.scala:43)
	at io.getquill.context.ContextMacro$class.translateStatic(ContextMacro.scala:51)
	at io.getquill.context.ContextMacro$class.translate(ContextMacro.scala:37)
	at io.getquill.context.ContextMacro$class.expand(ContextMacro.scala:24)
	at io.getquill.context.QueryMacro.expand(QueryMacro.scala:8)
	at io.getquill.context.QueryMacro.expandQueryWithMeta(QueryMacro.scala:118)
	at io.getquill.context.QueryMacro.expandQuery(QueryMacro.scala:37)
	at io.getquill.context.QueryMacro.runQuery(QueryMacro.scala:23)

Workaround

Use tuples to contain the embedded entities.

@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

No branches or pull requests

1 participant