LENS-905 : Group by is not promoted when keys projected along with having clause
Project: http://git-wip-us.apache.org/repos/asf/lens/repo Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/c1790813 Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/c1790813 Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/c1790813 Branch: refs/heads/current-release-line Commit: c17908134e004c646724d7e464252ec76a43113d Parents: d6aeecc Author: Sushil Mohanty <sushilmoha...@apache.org> Authored: Fri Dec 18 11:50:33 2015 +0530 Committer: Sushil Mohanty <sushilmoha...@apache.org> Committed: Fri Dec 18 11:50:33 2015 +0530 ---------------------------------------------------------------------- .../org/apache/lens/cube/parse/AggregateResolver.java | 4 +++- .../apache/lens/cube/parse/TestAggregateResolver.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lens/blob/c1790813/lens-cube/src/main/java/org/apache/lens/cube/parse/AggregateResolver.java ---------------------------------------------------------------------- diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/AggregateResolver.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/AggregateResolver.java index b544a67..39bd1cc 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/AggregateResolver.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/AggregateResolver.java @@ -97,7 +97,9 @@ class AggregateResolver implements ContextRewriter { Configuration distConf = cubeql.getConf(); boolean isDimOnlyDistinctEnabled = distConf.getBoolean(CubeQueryConfUtil.ENABLE_ATTRFIELDS_ADD_DISTINCT, CubeQueryConfUtil.DEFAULT_ATTR_FIELDS_ADD_DISTINCT); - if (isDimOnlyDistinctEnabled) { + //Having clause will always work with measures, if only keys projected + //query should skip distinct and promote group by. + if (cubeql.getHavingAST() == null && isDimOnlyDistinctEnabled) { // Check if any measure/aggregate columns and distinct clause used in // select tree. If not, update selectAST token "SELECT" to "SELECT DISTINCT" if (!hasMeasures(cubeql, cubeql.getSelectAST()) && !isDistinctClauseUsed(cubeql.getSelectAST()) http://git-wip-us.apache.org/repos/asf/lens/blob/c1790813/lens-cube/src/test/java/org/apache/lens/cube/parse/TestAggregateResolver.java ---------------------------------------------------------------------- diff --git a/lens-cube/src/test/java/org/apache/lens/cube/parse/TestAggregateResolver.java b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestAggregateResolver.java index a48d753..35234a1 100644 --- a/lens-cube/src/test/java/org/apache/lens/cube/parse/TestAggregateResolver.java +++ b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestAggregateResolver.java @@ -93,6 +93,9 @@ public class TestAggregateResolver extends TestQueryRewrite { String q10 = "SELECT cityid, round(testCube.msr2) from testCube where " + TWO_DAYS_RANGE; + //dimension selected with having + String q11 = "SELECT cityid from testCube where " + TWO_DAYS_RANGE + " having (testCube.msr2 > 100)"; + String expectedq1 = getExpectedQuery(cubeName, "SELECT testcube.cityid," + " sum(testCube.msr2) from ", null, "group by testcube.cityid", getWhereForDailyAndHourly2days(cubeName, "C2_testfact")); @@ -128,13 +131,17 @@ public class TestAggregateResolver extends TestQueryRewrite { String expectedq10 = getExpectedQuery(cubeName, "SELECT testcube.cityid," + " round(sum(testCube.msr2)) from ", null, "group by testcube.cityid", getWhereForDailyAndHourly2days(cubeName, "C2_testfact")); - + String expectedq11 = + getExpectedQuery(cubeName, "SELECT testcube.cityid from ", null, + "group by testcube.cityid" + "having sum(testCube.msr2) > 100", + getWhereForDailyAndHourly2days(cubeName, "C2_testfact")); String[] tests = { - q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, + q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, }; String[] expected = { expectedq1, expectedq2, expectedq3, expectedq4, expectedq5, expectedq6, expectedq7, expectedq8, expectedq9, expectedq10, + expectedq11, }; for (int i = 0; i < tests.length; i++) {