You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by am...@apache.org on 2016/07/29 04:41:38 UTC
lens git commit: LENS-1156 : Fix
TestUnionQueries.testDimAttrExpressionQuery test failure
Repository: lens
Updated Branches:
refs/heads/master e4d8b88f9 -> 3f03d29ba
LENS-1156 : Fix TestUnionQueries.testDimAttrExpressionQuery test failure
Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/3f03d29b
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/3f03d29b
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/3f03d29b
Branch: refs/heads/master
Commit: 3f03d29ba47755913e06cd3a397119c679b2f65a
Parents: e4d8b88
Author: Amareshwari Sriramadasu <am...@apache.org>
Authored: Fri Jul 29 10:11:32 2016 +0530
Committer: Amareshwari Sriramadasu <am...@apache.org>
Committed: Fri Jul 29 10:11:32 2016 +0530
----------------------------------------------------------------------
.../lens/cube/parse/TestUnionQueries.java | 176 +++++++++++--------
1 file changed, 100 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lens/blob/3f03d29b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestUnionQueries.java
----------------------------------------------------------------------
diff --git a/lens-cube/src/test/java/org/apache/lens/cube/parse/TestUnionQueries.java b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestUnionQueries.java
index f5657e5..d5bc81c 100644
--- a/lens-cube/src/test/java/org/apache/lens/cube/parse/TestUnionQueries.java
+++ b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestUnionQueries.java
@@ -218,96 +218,120 @@ public class TestUnionQueries extends TestQueryRewrite {
conf.set(getValidUpdatePeriodsKey("testfact", "C1"), "DAILY,HOURLY");
conf.set(getValidUpdatePeriodsKey("testfact2", "C1"), "YEARLY");
conf.set(getValidUpdatePeriodsKey("testfact", "C2"), "MONTHLY,DAILY");
- ArrayList<String> storages = Lists.newArrayList("c1_testfact", "c2_testfact");
- getStorageToUpdatePeriodMap().put("c1_testfact", Lists.newArrayList(HOURLY, DAILY));
- getStorageToUpdatePeriodMap().put("c2_testfact", Lists.newArrayList(MONTHLY));
- StoragePartitionProvider provider = new StoragePartitionProvider() {
- @Override
- public Map<String, String> providePartitionsForStorage(String storage) {
- return getWhereForMonthlyDailyAndHourly2monthsUnionQuery(storage);
- }
- };
+
String hqlQuery = rewrite("select asciicity as `City Name`, cityAndState as citystate, isIndia as isIndia,"
+ " msr8, msr7 as `Third measure` "
+ "from testCube where asciicity = 'c' and cityname = 'a' and zipcode = 'b' and "
+ TWO_MONTHS_RANGE_UPTO_HOURS, conf);
- String expected = getExpectedUnionQuery(TEST_CUBE_NAME, storages, provider,
- "SELECT testcube.alias0 as `City Name`, testcube.alias1 as citystate, testcube.alias2 as isIndia, "
- + "sum(testcube.alias3) + max(testcube.alias4), "
- + "case when sum(testcube.alias3) = 0 then 0 else sum(testcube.alias5)/sum(testcube.alias3) end "
- + "as `Third Measure`",
- null, " group by testcube.alias0, testcube.alias1, testcube.alias2",
- "select ascii(cubecity.name) as `alias0`, concat(cubecity.name, \":\", cubestate.name) as alias1,"
- + "cubecity.name == 'DELHI' OR cubestate.name == 'KARNATAKA' OR cubestate.name == 'MAHARASHTRA' as alias2,"
- + "sum(testcube.msr2) as `alias3`, max(testcube.msr3) as `alias4`, "
- + "sum(case when testcube.cityid = 'x' then testcube.msr21 else testcube.msr22 end) as `alias5`", " join "
- + getDbName() + "c1_statetable cubestate on testcube.stateid = cubestate.id and (cubestate.dt = 'latest') join"
- + getDbName() + "c1_citytable cubecity on testcube.cityid = cubecity.id and (cubecity.dt = 'latest')",
- "ascii(cubecity.name) = 'c' and cubecity.name = 'a' and testcube.zipcode = 'b'",
- " group by ascii(cubecity.name)), concat(cubecity.name, \":\", cubestate.name),"
- + "cubecity.name == 'DELHI' OR cubestate.name == 'KARNATAKA' OR cubestate.name == 'MAHARASHTRA'");
- compareQueries(hqlQuery, expected);
+ String joinExpr1 = " join "
+ + getDbName() + "c1_statetable cubestate on testcube.stateid = cubestate.id and (cubestate.dt = 'latest') join"
+ + getDbName() + "c1_citytable cubecity on testcube.cityid = cubecity.id and (cubecity.dt = 'latest')";
+ String joinExpr2 = " join "
+ + getDbName() + "c1_citytable cubecity on testcube.cityid = cubecity.id and (cubecity.dt = 'latest') join"
+ + getDbName() + "c1_statetable cubestate on testcube.stateid = cubestate.id and (cubestate.dt = 'latest')";
+
+ String expected1 = getExpectedQueryForDimAttrExpressionQuery(joinExpr1);
+ String expected2 = getExpectedQueryForDimAttrExpressionQuery(joinExpr2);
+ assertTrue(new TestQuery(hqlQuery).equals(new TestQuery(expected1))
+ || new TestQuery(hqlQuery).equals(new TestQuery(expected2)),
+ "Actual :" + hqlQuery + " Expected1:" + expected1 + " Expected2 : "+ expected2);
}
+ private String getExpectedQueryForDimAttrExpressionQuery(String joinExpr) {
+ try {
+ ArrayList<String> storages = Lists.newArrayList("c1_testfact", "c2_testfact");
+ getStorageToUpdatePeriodMap().put("c1_testfact", Lists.newArrayList(HOURLY, DAILY));
+ getStorageToUpdatePeriodMap().put("c2_testfact", Lists.newArrayList(MONTHLY));
+ StoragePartitionProvider provider = new StoragePartitionProvider() {
+ @Override
+ public Map<String, String> providePartitionsForStorage(String storage) {
+ return getWhereForMonthlyDailyAndHourly2monthsUnionQuery(storage);
+ }
+ };
+ return getExpectedUnionQuery(TEST_CUBE_NAME, storages, provider,
+ "SELECT testcube.alias0 as `City Name`, testcube.alias1 as citystate, testcube.alias2 as isIndia, "
+ + "sum(testcube.alias3) + max(testcube.alias4), "
+ + "case when sum(testcube.alias3) = 0 then 0 else sum(testcube.alias5)/sum(testcube.alias3) end "
+ + "as `Third Measure`",
+ null, " group by testcube.alias0, testcube.alias1, testcube.alias2",
+ "select ascii(cubecity.name) as `alias0`, concat(cubecity.name, \":\", cubestate.name) as alias1,"
+ + "cubecity.name == 'DELHI' OR cubestate.name == 'KARNATAKA' OR cubestate.name == 'MAHARASHTRA' as alias2,"
+ + "sum(testcube.msr2) as `alias3`, max(testcube.msr3) as `alias4`, "
+ + "sum(case when testcube.cityid = 'x' then testcube.msr21 else testcube.msr22 end) as `alias5`", joinExpr,
+ "ascii(cubecity.name) = 'c' and cubecity.name = 'a' and testcube.zipcode = 'b'",
+ " group by ascii(cubecity.name)), concat(cubecity.name, \":\", cubestate.name),"
+ + "cubecity.name == 'DELHI' OR cubestate.name == 'KARNATAKA' OR cubestate.name == 'MAHARASHTRA'");
+ } finally {
+ getStorageToUpdatePeriodMap().clear();
+ }
+ }
@Test
public void testNonAggregateOverAggregateFunction() throws Exception {
- Configuration conf = getConf();
- conf.set(getValidStorageTablesKey("testfact"), "C1_testFact,C2_testFact");
- conf.set(getValidUpdatePeriodsKey("testfact", "C1"), "DAILY,HOURLY");
- conf.set(getValidUpdatePeriodsKey("testfact2", "C1"), "YEARLY");
- conf.set(getValidUpdatePeriodsKey("testfact", "C2"), "MONTHLY,DAILY");
- ArrayList<String> storages = Lists.newArrayList("c1_testfact", "c2_testfact");
- getStorageToUpdatePeriodMap().put("c1_testfact", Lists.newArrayList(HOURLY, DAILY));
- getStorageToUpdatePeriodMap().put("c2_testfact", Lists.newArrayList(MONTHLY));
- StoragePartitionProvider provider = new StoragePartitionProvider() {
- @Override
- public Map<String, String> providePartitionsForStorage(String storage) {
- return getWhereForMonthlyDailyAndHourly2monthsUnionQuery(storage);
- }
- };
- String hqlQuery = rewrite("select cityid as `City ID`, msr3 as `Measure 3`, "
- + "round(SUM(msr2)) as `Measure 2` from testCube" + " where "
- + TWO_MONTHS_RANGE_UPTO_HOURS + " group by zipcode having msr4 > 10 order by cityid desc, stateid asc, zipcode "
- + "asc limit 5",
- conf);
- String expected = getExpectedUnionQuery(TEST_CUBE_NAME, storages, provider,
- "SELECT testcube.alias0 as `City ID`,max(testcube.alias1) as `Measure 3`,round(sum(testcube.alias2)) as "
- + "`Measure 2` ", null, "group by testcube.alias3 having count(testcube.alias4) > 10 "
- + "order by testcube.alias0 desc, testcube.alias5 asc, testcube.alias3 asc limit 5",
+ try {
+ Configuration conf = getConf();
+ conf.set(getValidStorageTablesKey("testfact"), "C1_testFact,C2_testFact");
+ conf.set(getValidUpdatePeriodsKey("testfact", "C1"), "DAILY,HOURLY");
+ conf.set(getValidUpdatePeriodsKey("testfact2", "C1"), "YEARLY");
+ conf.set(getValidUpdatePeriodsKey("testfact", "C2"), "MONTHLY,DAILY");
+ ArrayList<String> storages = Lists.newArrayList("c1_testfact", "c2_testfact");
+ getStorageToUpdatePeriodMap().put("c1_testfact", Lists.newArrayList(HOURLY, DAILY));
+ getStorageToUpdatePeriodMap().put("c2_testfact", Lists.newArrayList(MONTHLY));
+ StoragePartitionProvider provider = new StoragePartitionProvider() {
+ @Override
+ public Map<String, String> providePartitionsForStorage(String storage) {
+ return getWhereForMonthlyDailyAndHourly2monthsUnionQuery(storage);
+ }
+ };
+ String hqlQuery = rewrite("select cityid as `City ID`, msr3 as `Measure 3`, "
+ + "round(SUM(msr2)) as `Measure 2` from testCube" + " where "
+ + TWO_MONTHS_RANGE_UPTO_HOURS + " group by zipcode having msr4 > 10 order by cityid desc, stateid asc, zipcode "
+ + "asc limit 5",
+ conf);
+ String expected = getExpectedUnionQuery(TEST_CUBE_NAME, storages, provider,
+ "SELECT testcube.alias0 as `City ID`,max(testcube.alias1) as `Measure 3`,round(sum(testcube.alias2)) as "
+ + "`Measure 2` ", null, "group by testcube.alias3 having count(testcube.alias4) > 10 "
+ + "order by testcube.alias0 desc, testcube.alias5 asc, testcube.alias3 asc limit 5",
"SELECT testcube.cityid as `alias0`, max(testcube.msr3) as `alias1`, sum(testcube.msr2) as `alias2`, "
+ "testcube.zipcode as `alias3`, count(testcube .msr4) as `alias4`, (testcube.stateid) as `alias5` FROM ",
- null, "GROUP BY testcube.zipcode");
- compareQueries(hqlQuery, expected);
+ null, "GROUP BY testcube.zipcode");
+ compareQueries(hqlQuery, expected);
+ } finally {
+ getStorageToUpdatePeriodMap().clear();
+ }
}
@Test
public void testMultiFactMultiStorage() throws ParseException, LensException {
- Configuration conf = LensServerAPITestUtil.getConfigurationWithParams(getConf(),
- CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C1,C2",
- getValidStorageTablesKey("testfact"), "C1_testFact,C2_testFact",
- getValidUpdatePeriodsKey("testfact", "C1"), "HOURLY",
- getValidUpdatePeriodsKey("testfact", "C2"), "DAILY",
- getValidUpdatePeriodsKey("testfact2_raw", "C1"), "YEARLY",
- getValidUpdatePeriodsKey("testfact2_raw", "C2"), "YEARLY");
- CubeTestSetup.getStorageToUpdatePeriodMap().put("c1_testfact", Lists.newArrayList(HOURLY));
- CubeTestSetup.getStorageToUpdatePeriodMap().put("c2_testfact", Lists.newArrayList(DAILY));
- String whereCond = "zipcode = 'a' and cityid = 'b' and (" + TWO_DAYS_RANGE_SPLIT_OVER_UPDATE_PERIODS + ")";
- String hqlQuery = rewrite("select zipcode, count(msr4), sum(msr15) from testCube where " + whereCond, conf);
- System.out.println(hqlQuery);
- String possibleStart1 = "SELECT COALESCE(mq1.zipcode, mq2.zipcode) zipcode, mq1.expr2 `count(msr4)`,"
- + " mq2.expr3 `sum(msr15)` FROM ";
- String possibleStart2 = "SELECT COALESCE(mq1.zipcode, mq2.zipcode) zipcode, mq2.expr2 `count(msr4)`,"
- + " mq1.expr3 `sum(msr15)` FROM ";
-
- assertTrue(hqlQuery.startsWith(possibleStart1) || hqlQuery.startsWith(possibleStart2));
- compareContains(rewrite("select zipcode as `zipcode`, sum(msr15) as `expr3` from testcube where " + whereCond,
- conf), hqlQuery);
- compareContains(rewrite("select zipcode as `zipcode`, count(msr4) as `expr2` from testcube where " + whereCond,
- conf), hqlQuery);
- assertTrue(hqlQuery.endsWith("on mq1.zipcode <=> mq2.zipcode"));
- // No time_range_in should be remaining
- assertFalse(hqlQuery.contains("time_range_in"));
- //TODO: handle having after LENS-813, also handle for order by and limit
+ try {
+ Configuration conf = LensServerAPITestUtil.getConfigurationWithParams(getConf(),
+ CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C1,C2",
+ getValidStorageTablesKey("testfact"), "C1_testFact,C2_testFact",
+ getValidUpdatePeriodsKey("testfact", "C1"), "HOURLY",
+ getValidUpdatePeriodsKey("testfact", "C2"), "DAILY",
+ getValidUpdatePeriodsKey("testfact2_raw", "C1"), "YEARLY",
+ getValidUpdatePeriodsKey("testfact2_raw", "C2"), "YEARLY");
+ getStorageToUpdatePeriodMap().put("c1_testfact", Lists.newArrayList(HOURLY));
+ getStorageToUpdatePeriodMap().put("c2_testfact", Lists.newArrayList(DAILY));
+ String whereCond = "zipcode = 'a' and cityid = 'b' and (" + TWO_DAYS_RANGE_SPLIT_OVER_UPDATE_PERIODS + ")";
+ String hqlQuery = rewrite("select zipcode, count(msr4), sum(msr15) from testCube where " + whereCond, conf);
+ System.out.println(hqlQuery);
+ String possibleStart1 = "SELECT COALESCE(mq1.zipcode, mq2.zipcode) zipcode, mq1.expr2 `count(msr4)`,"
+ + " mq2.expr3 `sum(msr15)` FROM ";
+ String possibleStart2 = "SELECT COALESCE(mq1.zipcode, mq2.zipcode) zipcode, mq2.expr2 `count(msr4)`,"
+ + " mq1.expr3 `sum(msr15)` FROM ";
+
+ assertTrue(hqlQuery.startsWith(possibleStart1) || hqlQuery.startsWith(possibleStart2));
+ compareContains(rewrite("select zipcode as `zipcode`, sum(msr15) as `expr3` from testcube where " + whereCond,
+ conf), hqlQuery);
+ compareContains(rewrite("select zipcode as `zipcode`, count(msr4) as `expr2` from testcube where " + whereCond,
+ conf), hqlQuery);
+ assertTrue(hqlQuery.endsWith("on mq1.zipcode <=> mq2.zipcode"));
+ // No time_range_in should be remaining
+ assertFalse(hqlQuery.contains("time_range_in"));
+ //TODO: handle having after LENS-813, also handle for order by and limit
+ } finally {
+ getStorageToUpdatePeriodMap().clear();
+ }
}
@Test