Skip to content

Conversation

@deusaquilus
Copy link
Collaborator

SheathLeafClauses is buggy and fails for even simple examples like this:

  case class Parent(id: Int, name: String)
  case class Child(parentId: Int, name: String)

  val ids = quote {
    (for {
      p <- query[Parent]
      a <- query[Child].join(a => a.parentId == p.id)
    } yield p.id).distinct
  }

  val parentChildJoined = quote {
    for {
      id <- ids
      p  <- query[Parent].join(p => p.id == id)
      c  <- query[Child].join(c => c.parentId == p.id)
    } yield (p, c)
  }

Throws an error during beta reduction (TODO get the error).

We want to replace the logic with a more practical set of transforms that happen on SqlQuery since that is the place where it should mater that clauses cannot be primitive. The ideal place to do this is between SqlQuery and ExpandNestedQuery because at that time every single SqlQuery that has only one primitive-valued SelectValue (in the FlattenSqlQuery.select) must correspond to a type of situation resembling SELECT primitive FROM (SELECT x.primitive FROM ...) AS primitive. It makes it easier to turn the whole construct into something friendly to SQL like: SELECT primitive.value FROM (SELECT x.primitive AS value FROM ...) AS primitive.

@deusaquilus deusaquilus force-pushed the replace_SheathLeafClauses branch from 44486ae to 1a30b60 Compare July 4, 2024 04:22
@deusaquilus deusaquilus force-pushed the replace_SheathLeafClauses branch from 3b7f2f5 to abb7e08 Compare July 11, 2024 23:06
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 this pull request may close these issues.

3 participants