Skip to content

Commit

Permalink
add test cases for cubeExprs and rollupExprs
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangxb1987 committed Nov 6, 2016
1 parent 4df9a42 commit ef3a733
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,7 @@ class Analyzer(
* We need to get all of its subsets for the rule described above, the subset is
* represented as sequence of expressions.
*/
def rollupExprs(exprs: Seq[Expression]): Seq[Seq[Expression]] = {
val buffer = ArrayBuffer.empty[Seq[Expression]]
var current = exprs
while (current.nonEmpty) {
buffer += current
current = current.init
}
buffer += Seq.empty
}
def rollupExprs(exprs: Seq[Expression]): Seq[Seq[Expression]] = exprs.inits.toSeq

/*
* GROUP BY a, b, c WITH CUBE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ class ResolveGroupingAnalyticsSuite extends AnalysisTest {
lazy val nulStr = Literal(null, StringType)
lazy val r1 = LocalRelation(a, b, c)

test("rollupExprs") {
val testRollup = (exprs: Seq[Expression], rollup: Seq[Seq[Expression]]) => {
val result = SimpleAnalyzer.ResolveGroupingAnalytics.rollupExprs(exprs)
assert(result.sortBy(_.hashCode) == rollup.sortBy(_.hashCode))
}

testRollup(Seq(a, b, c), Seq(Seq(), Seq(a), Seq(a, b), Seq(a, b, c)))
testRollup(Seq(c, b, a), Seq(Seq(), Seq(c), Seq(c, b), Seq(c, b, a)))
testRollup(Seq(a), Seq(Seq(), Seq(a)))
testRollup(Seq(), Seq(Seq()))
}

test("cubeExprs") {
val testCube = (exprs: Seq[Expression], cube: Seq[Seq[Expression]]) => {
val result = SimpleAnalyzer.ResolveGroupingAnalytics.cubeExprs(exprs)
assert(result.sortBy(_.hashCode) == cube.sortBy(_.hashCode))
}

testCube(Seq(a, b, c),
Seq(Seq(), Seq(a), Seq(b), Seq(c), Seq(a, b), Seq(a, c), Seq(b, c), Seq(a, b, c)))
testCube(Seq(c, b, a),
Seq(Seq(), Seq(a), Seq(b), Seq(c), Seq(c, b), Seq(c, a), Seq(b, a), Seq(c, b, a)))
testCube(Seq(a), Seq(Seq(), Seq(a)))
testCube(Seq(), Seq(Seq()))
}

test("grouping sets") {
val originalPlan = GroupingSets(Seq(Seq(), Seq(unresolved_a), Seq(unresolved_a, unresolved_b)),
Seq(unresolved_a, unresolved_b), r1,
Expand Down

0 comments on commit ef3a733

Please sign in to comment.