Skip to content

Commit

Permalink
Merge pull request #472 from jilen/fix_distinct
Browse files Browse the repository at this point in the history
create sub query if aggregation on distinct query
  • Loading branch information
fwbrasil authored Jul 24, 2016
2 parents 10c227c + ca83abc commit 1f823d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ object SqlQuery {
case Aggregation(op, q: Query) =>
val b = flatten(q, alias)
b.select match {
case head :: Nil =>
case head :: Nil if !b.distinct =>
b.copy(select = List(head.copy(ast = Aggregation(op, head.ast))))
case other =>
FlattenSqlQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class SqlIdiomSpec extends Spec {
testContext.run(q).sql mustEqual
"SELECT x + 1 FROM (SELECT DISTINCT i.i FROM TestEntity i) x"
}
"distinct followed by aggregation" in {
val q = quote {
qr1.map(i => i.i).distinct.size
}
testContext.run(q).sql mustEqual
"SELECT COUNT(*) FROM (SELECT DISTINCT i.i FROM TestEntity i) x"
}
}
"sorted" - {
"simple" in {
Expand Down

0 comments on commit 1f823d6

Please sign in to comment.