Skip to content

Commit

Permalink
Removed aliases to grouping expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ravipesala committed Oct 2, 2014
1 parent f8ace79 commit 9fb973f
Showing 1 changed file with 1 addition and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,6 @@ class SqlParser extends StandardTokenParsers with PackratParsers {
case (e, i) => Alias(e, s"c$i")()
}
}

/** Creates the aliases to the grouping expressions */
protected def assignAliasesForGroups(
grpExprs: Seq[Expression],
projExprs: Seq[Expression]): Seq[NamedExpression] = {
grpExprs.zipWithIndex.map {
case (ne: NamedExpression, _) => ne
case (e, i) =>
var aliasForGrp:NamedExpression = null
projExprs.foreach {
case Alias(pe,pi) if pe.fastEquals(e) => aliasForGrp = Alias(e, pi)()
case _ =>
}
if (aliasForGrp == null) {
Alias(e, s"c$i")()
} else {
aliasForGrp
}
}
}

protected lazy val query: Parser[LogicalPlan] = (
select * (
Expand All @@ -186,7 +166,7 @@ class SqlParser extends StandardTokenParsers with PackratParsers {
val withFilter = f.map(f => Filter(f, base)).getOrElse(base)
val withProjection =
g.map {g =>
Aggregate(assignAliasesForGroups(g,p), assignAliases(p), withFilter)
Aggregate(g, assignAliases(p), withFilter)
}.getOrElse(Project(assignAliases(p), withFilter))
val withDistinct = d.map(_ => Distinct(withProjection)).getOrElse(withProjection)
val withHaving = h.map(h => Filter(h, withDistinct)).getOrElse(withDistinct)
Expand Down

0 comments on commit 9fb973f

Please sign in to comment.