Skip to content

Commit

Permalink
remove from-recursion not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
deusaquilus committed Jul 11, 2024
1 parent 1a30b60 commit 3b7f2f5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ final case class FlattenSqlQuery(

def mapAsts(f: Ast => Ast): FlattenSqlQuery =
copy(
from = from.map(_.mapAst(f)),
where = where.map(f),
groupBy = groupBy.map(f),
orderBy = orderBy.map(o => o.copy(ast = f(o.ast))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ case class ValueizeSingleLeafSelects(strategy: NamingStrategy) extends Stateless
// Turn every `SELECT primitive-x` into a `SELECT case-class-x.primitive-value`
override protected def expandNested(q: FlattenSqlQuery, level: QueryLevel): FlattenSqlQuery = {
// get the alises before we transform (i.e. Valueize) the contexts inside turning the leaf-quat alises into product-quat alises
val fromContextAliases = collectAliases(q.from).filter(!_.quat.isProduct)
val leafValuedFroms = collectAliases(q.from).filter(!_.quat.isProduct)
// now transform the inner clauses
val from = q.from.map(expandContext(_))

def containsAlias(ast: Ast): Boolean =
CollectAst.byType[Ident](ast).exists(id => fromContextAliases.contains(id))
CollectAst.byType[Ident](ast).exists(id => leafValuedFroms.contains(id))

// If there is one single select clause that has a primitive (i.e. Leaf) quat then we can alias it to "value"
// This is the case of `SELECT primitive FROM (SELECT p.age from Person p) AS primitive`
Expand All @@ -40,7 +40,7 @@ case class ValueizeSingleLeafSelects(strategy: NamingStrategy) extends Stateless
val valuizedQuery =
q.copy(from = from)(q.quat).mapAsts { ast =>
if (containsAlias(ast)) {
val reductions = CollectAst.byType[Ident](ast).filter(id => fromContextAliases.contains(id)).map(id => id -> valueize(id))
val reductions = CollectAst.byType[Ident](ast).filter(id => leafValuedFroms.contains(id)).map(id => id -> valueize(id))
BetaReduction(ast, TypeBehavior.ReplaceWithReduction, reductions: _*)
} else {
ast
Expand Down

0 comments on commit 3b7f2f5

Please sign in to comment.