Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1920 from deusaquilus2/quat_base_subquery_compressed
Change Subquery Expansion to be Quat-based
- Loading branch information
Showing
37 changed files
with
1,368 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
quill-spark/src/main/scala/io/getquill/context/spark/SimpleNestedExpansion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.getquill.context.spark | ||
|
||
import io.getquill.ast._ | ||
import io.getquill.context.sql._ | ||
import io.getquill.sql.norm.StatelessQueryTransformer | ||
|
||
object TopLevelExpansion { | ||
|
||
implicit class AliasOp(alias: Option[String]) { | ||
def concatWith(str: String): Option[String] = | ||
alias.orElse(Some("")).map(v => s"${v}${str}") | ||
} | ||
|
||
def apply(values: List[SelectValue]): List[SelectValue] = | ||
values.flatMap(apply(_)) | ||
|
||
private def apply(value: SelectValue): List[SelectValue] = { | ||
value match { | ||
case SelectValue(Tuple(values), alias, concat) => | ||
values.zipWithIndex.map { | ||
case (ast, i) => | ||
SelectValue(ast, alias.concatWith(s"_${i + 1}"), concat) | ||
} | ||
// case SelectValue(CaseClass(fields), alias, concat) => | ||
// fields.flatMap { | ||
// case (name, ast) => | ||
// apply(SelectValue(ast, alias.concatWith(name), concat)) | ||
// } | ||
// Direct infix select, etc... | ||
case other => List(other) | ||
} | ||
} | ||
} | ||
|
||
object SimpleNestedExpansion extends StatelessQueryTransformer { | ||
|
||
protected override def apply(q: SqlQuery, isTopLevel: Boolean = false): SqlQuery = | ||
q match { | ||
case q: FlattenSqlQuery => | ||
expandNested(q.copy(select = TopLevelExpansion(q.select))(q.quat), isTopLevel) | ||
case other => | ||
super.apply(q, isTopLevel) | ||
} | ||
|
||
protected override def expandNested(q: FlattenSqlQuery, isTopLevel: Boolean): FlattenSqlQuery = | ||
q match { | ||
case FlattenSqlQuery(from, where, groupBy, orderBy, limit, offset, select, distinct) => | ||
val newFroms = q.from.map(expandContext(_)) | ||
|
||
def distinctIfNotTopLevel(values: List[SelectValue]) = | ||
if (isTopLevel) | ||
values | ||
else | ||
values.distinct | ||
|
||
val distinctSelects = | ||
distinctIfNotTopLevel(select) | ||
|
||
q.copy(select = distinctSelects, from = newFroms)(q.quat) | ||
} | ||
} |
Oops, something went wrong.