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

Encountering error "Unexpected node in ResultSetMapping: OptionApply" in agg function #1796

Open
zgrannan opened this issue Oct 20, 2017 · 1 comment
Milestone

Comments

@zgrannan
Copy link
Contributor

This error appears to occur when using OptionApply in an aggregate function. Casting the column using .asColumnOf[Option[T]] seems to be a workaround in some cases.

I made a branch with the failing test added here: https://github.com/zgrannan/slick/tree/testOptionApply

An example (the added test) is below. It's kind of a contrived example but I am encountering this error in production as part of a more complex function.

  def testOptionApply = {

    case class LiftedB(
      a: Rep[Option[Long]],
      b: Rep[Option[Long]],
      c: Rep[Option[Long]]
    )

    case class B(
      a: Option[Long],
      b: Option[Long],
      c: Option[Long]
    )

    implicit object shape
        extends CaseClassShape((LiftedB.apply _).tupled,
                             (B.apply _).tupled)

    case class ARow(id: Int, s: Long)

    class A(tag: Tag) extends Table[ARow](tag, "A_TestOptionApply") {
      def id = column[Int]("id", O.PrimaryKey)
      def s = column[Long]("s")
      def * = (id, s).mapTo[ARow]
    }
    val as = TableQuery[A]
    val data = Seq(ARow(1, 1L), ARow(2, 2L))

    as.schema.create >>
      (as ++= data) >>
      (as.length, LiftedB(
        as.map(_.s).sum.getOrElse(0L).?,
        as.map(_.s).sum.getOrElse(0L).?,
        as.map(_.s).sum.getOrElse(0L).?
      )).result.map (
        _._1 shouldBe 2
      )
  }
@hvesalai
Copy link
Member

If you can, please post a PR to fix this.

@hvesalai hvesalai added this to the Future milestone Feb 28, 2018
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

2 participants