Example usage for org.apache.hadoop.conf Configuration setBoolean

List of usage examples for org.apache.hadoop.conf Configuration setBoolean

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration setBoolean.

Prototype

public void setBoolean(String name, boolean value) 

Source Link

Document

Set the value of the name property to a boolean.

Usage

From source file:org.apache.lens.cube.parse.TestBridgeTableQueries.java

License:Apache License

@Test
public void testBridgeTablesWithExpressionAndAliasesAfterFlattening() throws Exception {
    Configuration conf = new Configuration(hConf);
    conf.setBoolean(CubeQueryConfUtil.DO_FLATTENING_OF_BRIDGE_TABLE_EARLY, true);
    String query = "select usersports.name as uname, substr(usersports.name, 3) as `sub user`,"
            + " sum(msr2) from basecube where " + TWO_DAYS_RANGE + " and usersports.name = 'CRICKET,FOOTBALL'";
    String hqlQuery = rewrite(query, conf);
    String expected = getExpectedQuery("basecube",
            "select usersports.name as `uname`, substr(usersports.name, 3) as "
                    + "`sub user`, sum(basecube.msr2) FROM ",
            " join " + getDbName() + "c1_usertable userdim ON basecube.userid = userdim.id "
                    + " join (select user_interests.user_id as user_id,collect_set(usersports.name) as name"
                    + " from " + getDbName() + "c1_user_interests_tbl user_interests" + " join " + getDbName()
                    + "c1_sports_tbl usersports on user_interests.sport_id = usersports.id"
                    + " group by user_interests.user_id) usersports" + " on userdim.id = usersports.user_id ",
            null,//from  w w w. java 2  s . com
            " and usersports.name = 'CRICKET,FOOTBALL' group by usersports.name, substr(usersports.name, 3)",
            null, getWhereForDailyAndHourly2days("basecube", "c1_testfact1_base"));
    TestCubeRewriter.compareQueries(hqlQuery, expected);
    // run with chain ref column
    query = "select sports as uname, sports_abbr as `sub user`, sum(msr2) from basecube where " + TWO_DAYS_RANGE
            + " and sports = 'CRICKET,FOOTBALL'";
    hqlQuery = rewrite(query, conf);
    TestCubeRewriter.compareQueries(hqlQuery, expected);
}

From source file:org.apache.lens.cube.parse.TestBridgeTableQueries.java

License:Apache License

@Test
public void testBridgeTablesWithMultipleFactsWithExprAfterFlattening() throws Exception {
    Configuration conf = new Configuration(hConf);
    conf.setBoolean(CubeQueryConfUtil.DO_FLATTENING_OF_BRIDGE_TABLE_EARLY, true);
    String query = "select substr(usersports.name, 3), msr2, msr12 from basecube where " + TWO_DAYS_RANGE
            + " and usersports.name = 'CRICKET,FOOTBALL'";
    String hqlQuery = rewrite(query, conf);
    String expected1 = getExpectedQuery("basecube",
            "select substr(usersports.name, 3) as `expr1`, sum(basecube.msr2) as `msr2` FROM ",
            " join " + getDbName() + "c1_usertable userdim ON basecube.userid = userdim.id "
                    + " join (select user_interests.user_id as user_id,collect_set(usersports.name) as name"
                    + " from " + getDbName() + "c1_user_interests_tbl user_interests" + " join " + getDbName()
                    + "c1_sports_tbl usersports on user_interests.sport_id = usersports.id"
                    + " group by user_interests.user_id) usersports" + " on userdim.id = usersports.user_id ",
            null, " and usersports.name = 'CRICKET,FOOTBALL' group by substr(usersports.name, 3)", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact1_base"));
    String expected2 = getExpectedQuery("basecube",
            "select substr(usersports.name, 3) as `expr1`, sum(basecube.msr12) as `msr12` FROM ",
            " join " + getDbName() + "c1_usertable userdim ON basecube.userid = userdim.id "
                    + " join (select user_interests.user_id as user_id,collect_set(usersports.name) as name"
                    + " from " + getDbName() + "c1_user_interests_tbl user_interests" + " join " + getDbName()
                    + "c1_sports_tbl usersports on user_interests.sport_id = usersports.id"
                    + " group by user_interests.user_id) usersports" + " on userdim.id = usersports.user_id ",
            null, " and usersports.name = 'CRICKET,FOOTBALL' group by substr(usersports.name, 3)", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact2_base"));
    TestCubeRewriter.compareContains(expected1, hqlQuery);
    TestCubeRewriter.compareContains(expected2, hqlQuery);
    String lower = hqlQuery.toLowerCase();
    assertTrue(lower/* w ww . j  a  v a2 s. c o  m*/
            .startsWith("select coalesce(mq1.expr1, mq2.expr1) `substr((usersports.name), 3)`,"
                    + " mq2.msr2 msr2, mq1.msr12 msr12 from ")
            || lower.startsWith(
                    "select coalesce(mq1.expr1, mq2.expr1) `substr((usersports.name), 3)`, mq1.msr2 msr2,"
                            + " mq2.msr12 msr12 from "),
            hqlQuery);

    assertTrue(hqlQuery.contains("mq1 full outer join ") && hqlQuery.endsWith("mq2 on mq1.expr1 <=> mq2.expr1"),
            hqlQuery);
    // run with chain ref column
    query = "select sports_abbr, msr2, msr12 from basecube where " + TWO_DAYS_RANGE + " and sports = "
            + "'CRICKET,FOOTBALL'";
    hqlQuery = rewrite(query, conf);
    expected1 = getExpectedQuery("basecube",
            "select substr(usersports.name, 3) as `sports_abbr`, sum(basecube.msr2) as `msr2` FROM ",
            " join " + getDbName() + "c1_usertable userdim ON basecube.userid = userdim.id "
                    + " join (select user_interests.user_id as user_id,collect_set(usersports.name) as name"
                    + " from " + getDbName() + "c1_user_interests_tbl user_interests" + " join " + getDbName()
                    + "c1_sports_tbl usersports on user_interests.sport_id = usersports.id"
                    + " group by user_interests.user_id) usersports" + " on userdim.id = usersports.user_id ",
            null, " and usersports.name = 'CRICKET,FOOTBALL' group by substr(usersports.name, 3)", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact1_base"));
    expected2 = getExpectedQuery("basecube",
            "select substr(usersports.name, 3) as `sports_abbr`, sum(basecube.msr12) as `msr12` FROM ",
            " join " + getDbName() + "c1_usertable userdim ON basecube.userid = userdim.id "
                    + " join (select user_interests.user_id as user_id,collect_set(usersports.name) as name"
                    + " from " + getDbName() + "c1_user_interests_tbl user_interests" + " join " + getDbName()
                    + "c1_sports_tbl usersports on user_interests.sport_id = usersports.id"
                    + " group by user_interests.user_id) usersports" + " on userdim.id = usersports.user_id ",
            null, " and usersports.name = 'CRICKET,FOOTBALL' group by substr(usersports.name, 3)", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact2_base"));
    TestCubeRewriter.compareContains(expected1, hqlQuery);
    TestCubeRewriter.compareContains(expected2, hqlQuery);
    lower = hqlQuery.toLowerCase();
    assertTrue(lower.startsWith(
            "select coalesce(mq1.sports_abbr, mq2.sports_abbr) sports_abbr, mq2.msr2 msr2, mq1.msr12 msr12 from ")
            || lower.startsWith(
                    "select coalesce(mq1.sports_abbr, mq2.sports_abbr) sports_abbr, mq1.msr2 msr2, mq2.msr12 msr12 from "),
            hqlQuery);

    assertTrue(hqlQuery.contains("mq1 full outer join ")
            && hqlQuery.endsWith("mq2 on mq1.sports_abbr <=> mq2.sports_abbr"), hqlQuery);
}

From source file:org.apache.lens.cube.parse.TestCubeRewriter.java

License:Apache License

@Test
public void testMaxCoveringFact() throws Exception {
    Configuration conf = getConf();
    conf.setClass(CubeQueryConfUtil.TIME_RANGE_WRITER_CLASS, AbridgedTimeRangeWriter.class,
            TimeRangeWriter.class);
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false);
    conf.set(DRIVER_SUPPORTED_STORAGES, "C1,C2,C4");
    CubeQueryContext cubeQueryContext = rewriteCtx("select SUM(msr2) from testCube where " + THIS_YEAR_RANGE,
            conf);//from w w  w . j a v  a2s . c  o  m
    PruneCauses<CubeFactTable> pruneCause = cubeQueryContext.getFactPruningMsgs();
    int lessDataCauses = 0;
    for (Map.Entry<CubeFactTable, List<CandidateTablePruneCause>> entry : pruneCause.entrySet()) {
        for (CandidateTablePruneCause cause : entry.getValue()) {
            if (cause.getCause().equals(LESS_DATA)) {
                lessDataCauses++;
            }
        }
    }
    assertTrue(lessDataCauses > 0);
}

From source file:org.apache.lens.cube.parse.TestCubeRewriter.java

License:Apache License

@Test
public void testLightestFactFirst() throws Exception {
    // testFact is lighter than testFact2.
    String hqlQuery = rewrite("select SUM(msr2) from testCube where " + TWO_DAYS_RANGE,
            getConfWithStorages("C2"));
    String expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);/*from w ww. ja  v a2  s  .co m*/

    Configuration conf = getConfWithStorages("C1");
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, true);
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForHourly2days("c1_testfact2"));
    compareQueries(hqlQuery, expected);

    conf.setBoolean(CubeQueryConfUtil.LIGHTEST_FACT_FIRST, true);

    LensException th = getLensExceptionInRewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE,
            conf);
    assertEquals(th.getErrorCode(),
            LensCubeErrorCode.NO_CANDIDATE_FACT_AVAILABLE.getLensErrorInfo().getErrorCode());
    NoCandidateFactAvailableException ne = (NoCandidateFactAvailableException) th;
    PruneCauses.BriefAndDetailedError pruneCauses = ne.getJsonMessage();
    int endIndex = MISSING_PARTITIONS.errorFormat.length() - 3;
    assertEquals(pruneCauses.getBrief().substring(0, endIndex),
            MISSING_PARTITIONS.errorFormat.substring(0, endIndex));
    assertEquals(pruneCauses.getDetails().get("testfact").size(), 1);
    assertEquals(pruneCauses.getDetails().get("testfact").iterator().next().getCause(), MISSING_PARTITIONS);
}

From source file:org.apache.lens.cube.parse.TestCubeRewriter.java

License:Apache License

@Test
public void testDerivedCube() throws ParseException, LensException, HiveException, ClassNotFoundException {
    CubeQueryContext rewrittenQuery = rewriteCtx("select SUM(msr2) from derivedCube where " + TWO_DAYS_RANGE,
            getConfWithStorages("C2"));
    String expected = getExpectedQuery(DERIVED_CUBE_NAME, "select sum(derivedCube.msr2) FROM ", null, null,
            getWhereForDailyAndHourly2days(DERIVED_CUBE_NAME, "C2_testfact"));
    compareQueries(rewrittenQuery.toHQL(), expected);
    System.out.println("Non existing parts:" + rewrittenQuery.getNonExistingParts());
    assertNotNull(rewrittenQuery.getNonExistingParts());

    LensException th = getLensExceptionInRewrite("select SUM(msr4) from derivedCube where " + TWO_DAYS_RANGE,
            getConf());//from w  ww  .  j a v  a 2 s.  co  m
    assertEquals(th.getErrorCode(), LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo().getErrorCode());

    // test join
    Configuration conf = getConf();
    conf.setBoolean(DISABLE_AUTO_JOINS, false);
    String hqlQuery;

    /*
    Accessing join chains from derived cubes are not supported yet.
    hqlQuery = rewrite("select dim2chain.name, SUM(msr2) from derivedCube where " + TWO_DAYS_RANGE, conf);
    expected =
      getExpectedQuery(DERIVED_CUBE_NAME, "select dim2chain.name, sum(derivedCube.msr2) FROM ", " JOIN "
          + getDbName() + "c1_testdim2tbl dim2chain ON derivedCube.dim2 = "
          + " dim2chain.id and (dim2chain.dt = 'latest') ", null, "group by (dim2chain.name)", null,
        getWhereForDailyAndHourly2days(DERIVED_CUBE_NAME, "c1_summary2"));
    compareQueries(hqlQuery, expected);
            
    // Test that explicit join query passes with join resolver disabled
    conf.setBoolean(DISABLE_AUTO_JOINS, true);
    hqlQuery =
      rewrite("select citydim.name, SUM(msr2) from derivedCube "
        + " inner join citydim on derivedCube.cityid = citydim.id where " + TWO_DAYS_RANGE, conf);
    expected =
      getExpectedQuery(DERIVED_CUBE_NAME, "select citydim.name, sum(derivedCube.msr2) FROM ",
        " inner JOIN " + getDbName()
        + "c1_citytable citydim ON derivedCube.cityid = citydim.id  and (citydim.dt = 'latest')", null,
        "group by (citydim.name)", null,
        getWhereForDailyAndHourly2days(DERIVED_CUBE_NAME, "c1_summary2"));
    compareQueries(hqlQuery, expected);*/
}

From source file:org.apache.lens.cube.parse.TestCubeRewriter.java

License:Apache License

@Test
public void testCubeWhereQuery() throws Exception {
    String hqlQuery, expected;/*  ww  w.ja v a  2 s  .  c om*/
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE,
            getConfWithStorages("C2"));
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    // Test with partition existence
    Configuration conf = getConf();
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, true);
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForHourly2days("c1_testfact2"));
    compareQueries(hqlQuery, expected);
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false);

    // Tests for valid tables
    conf.set(CubeQueryConfUtil.getValidFactTablesKey(TEST_CUBE_NAME), "testFact");
    conf.set(DRIVER_SUPPORTED_STORAGES, "C1");
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C1_testfact"));
    compareQueries(hqlQuery, expected);

    conf.set(DRIVER_SUPPORTED_STORAGES, "C2");
    conf.set(CubeQueryConfUtil.getValidFactTablesKey(TEST_CUBE_NAME), "testFact");
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    conf.set(DRIVER_SUPPORTED_STORAGES, "C1");
    conf.set(CubeQueryConfUtil.getValidFactTablesKey(TEST_CUBE_NAME), "testFact2");
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForHourly2days("c1_testfact2"));
    compareQueries(hqlQuery, expected);

    conf.set(DRIVER_SUPPORTED_STORAGES, "C1");
    conf.set(CubeQueryConfUtil.getValidFactTablesKey(TEST_CUBE_NAME), "testFact2");
    conf.set(getValidStorageTablesKey("testFact2"), "C1_testFact2");
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForHourly2days("c1_testfact2"));
    compareQueries(hqlQuery, expected);

    conf.set(CubeQueryConfUtil.getValidFactTablesKey(TEST_CUBE_NAME), "testFact");
    conf.set(getValidStorageTablesKey("testfact"), "C1_testFact");
    conf.set(getValidUpdatePeriodsKey("testfact", "C1"), "HOURLY");
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForHourly2days("c1_testfact"));
    compareQueries(hqlQuery, expected);

    conf.set(DRIVER_SUPPORTED_STORAGES, "C2");
    conf.set(getValidStorageTablesKey("testfact"), "C2_testFact");
    conf.set(getValidUpdatePeriodsKey("testfact", "C2"), "HOURLY");
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForHourly2days("c2_testfact"));
    compareQueries(hqlQuery, expected);

    // max interval test
    conf = new Configuration();
    conf.set(CubeQueryConfUtil.QUERY_MAX_INTERVAL, "HOURLY");
    conf.set(DRIVER_SUPPORTED_STORAGES, "C1,C2");
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select sum(testcube.msr2) FROM ", null, null,
            getWhereForHourly2days("c1_testfact2"));
    compareQueries(hqlQuery, expected);
}

From source file:org.apache.lens.cube.parse.TestCubeRewriter.java

License:Apache License

@Test
public void testPartColAsQueryColumn() throws Exception {
    Configuration conf = getConf();
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false);
    conf.set(DRIVER_SUPPORTED_STORAGES, "C3");
    conf.setBoolean(DISABLE_AUTO_JOINS, false);
    String hql, expected;/*from ww w .jav a2s.c om*/
    hql = rewrite("select cubecountry.name, msr2 from" + " testCube" + " where cubecountry.region = 'asia' and "
            + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select cubecountry.name, sum(testcube.msr2)" + " FROM ",
            " JOIN " + getDbName()
                    + "c3_countrytable_partitioned cubecountry on testcube.countryid=cubecountry.id and cubecountry.dt='latest'",
            "cubecountry.region='asia'", " group by cubecountry.name ", null,
            getWhereForHourly2days(TEST_CUBE_NAME, "C3_testfact2_raw"));
    compareQueries(hql, expected);
    hql = rewrite("select cubestate.name, cubestate.countryid, msr2 from" + " testCube"
            + " where cubestate.countryid = 5 and " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME,
            "select cubestate.name, cubestate.countryid, sum(testcube.msr2)" + " FROM ",
            " JOIN " + getDbName() + "c3_statetable_partitioned cubestate ON"
                    + " testCube.stateid = cubestate.id and cubestate.dt = 'latest'",
            "cubestate.countryid=5", " group by cubestate.name, cubestate.countryid", null,
            getWhereForHourly2days(TEST_CUBE_NAME, "C3_testfact2_raw"));
    compareQueries(hql, expected);
}

From source file:org.apache.lens.cube.parse.TestCubeRewriter.java

License:Apache License

@Test
public void testConvertDimFilterToFactFilterForSingleFact() throws Exception {
    Configuration conf = getConf();
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false);
    conf.set(DRIVER_SUPPORTED_STORAGES, "C3");
    conf.setBoolean(DISABLE_AUTO_JOINS, false);
    conf.setBoolean(REWRITE_DIM_FILTER_TO_FACT_FILTER, true);

    // filter with =
    String hql = rewrite("select cubecountry.name, msr2 from" + " testCube"
            + " where cubecountry.region = 'asia' and " + TWO_DAYS_RANGE, conf);
    String filterSubquery = "testcube.countryid in ( select id from TestQueryRewrite.c3_countrytable_partitioned "
            + "cubecountry where ((cubecountry.region) = 'asia') and (cubecountry.dt = 'latest') )";
    assertTrue(hql.contains(filterSubquery));

    // filter with or
    hql = rewrite("select cubecountry.name, msr2 from" + " testCube" + " where (cubecountry.region = 'asia' "
            + "or cubecountry.region = 'europe') and " + TWO_DAYS_RANGE, conf);
    filterSubquery = "testcube.countryid in ( select id from TestQueryRewrite.c3_countrytable_partitioned "
            + "cubecountry where (((cubecountry.region) = 'asia') or ((cubecountry.region) = 'europe')) "
            + "and (cubecountry.dt = 'latest') )";
    assertTrue(hql.contains(filterSubquery));

    //filter with in
    hql = rewrite("select cubecountry.name, msr2 from" + " testCube"
            + " where cubecountry.region in ('asia','europe') " + "and " + TWO_DAYS_RANGE, conf);
    filterSubquery = "testcube.countryid in ( select id from TestQueryRewrite.c3_countrytable_partitioned "
            + "cubecountry where (cubecountry.region) in ('asia' , 'europe') and (cubecountry.dt = 'latest') )";
    assertTrue(hql.contains(filterSubquery));

    //filter with not in
    hql = rewrite("select cubecountry.name, msr2 from" + " testCube"
            + " where cubecountry.region not in ('asia','europe') " + "and " + TWO_DAYS_RANGE, conf);
    filterSubquery = "testcube.countryid in ( select id from TestQueryRewrite.c3_countrytable_partitioned "
            + "cubecountry where (cubecountry.region) not  in ('asia' , 'europe') and (cubecountry.dt = 'latest') )";
    assertTrue(hql.contains(filterSubquery));

    //filter with !=
    hql = rewrite("select cubecountry.name, msr2 from" + " testCube" + " where cubecountry.region != 'asia' "
            + "and " + TWO_DAYS_RANGE, conf);
    filterSubquery = "testcube.countryid in ( select id from TestQueryRewrite.c3_countrytable_partitioned "
            + "cubecountry where ((cubecountry.region) != 'asia') and (cubecountry.dt = 'latest') )";
    assertTrue(hql.contains(filterSubquery));

    //filter with cube alias
    hql = rewrite("select cubecountry.name, msr2 from" + " testCube as t"
            + " where cubecountry.region = 'asia' " + "and zipcode = 'x' and " + TWO_DAYS_RANGE, conf);
    filterSubquery = "t.countryid in ( select id from TestQueryRewrite.c3_countrytable_partitioned "
            + "cubecountry where ((cubecountry.region) = 'asia') and (cubecountry.dt = 'latest') )";
    assertTrue(hql.contains(filterSubquery));

    //filter with AbridgedTimeRangeWriter
    conf.setClass(CubeQueryConfUtil.TIME_RANGE_WRITER_CLASS, AbridgedTimeRangeWriter.class,
            TimeRangeWriter.class);
    hql = rewrite("select cubecountry.name, msr2 from" + " testCube" + " where cubecountry.region = 'asia' and "
            + TWO_DAYS_RANGE, conf);/* ww  w  .j a  v a2  s  . com*/
    filterSubquery = "testcube.countryid in ( select id from TestQueryRewrite.c3_countrytable_partitioned "
            + "cubecountry where ((cubecountry.region) = 'asia') and (cubecountry.dt = 'latest') )";
    String timeKeyIn = "(testcube.dt) in";
    assertTrue(hql.contains(timeKeyIn));
    assertTrue(hql.contains(filterSubquery));
}

From source file:org.apache.lens.cube.parse.TestCubeRewriter.java

License:Apache License

@Test
public void testCubeGroupbyQuery() throws Exception {
    Configuration conf = getConf();
    conf.set(DRIVER_SUPPORTED_STORAGES, "C2");

    String hqlQuery = rewrite("select name, SUM(msr2) from"
            + " testCube join citydim on testCube.cityid = citydim.id where " + TWO_DAYS_RANGE, conf);
    String expected = getExpectedQuery(TEST_CUBE_NAME, "select citydim.name," + " sum(testcube.msr2) FROM ",
            "INNER JOIN " + getDbName() + "c2_citytable citydim ON" + " testCube.cityid = citydim.id", null,
            " group by citydim.name ", null, getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);/*from ww  w  .  j  a  va2s. c om*/

    hqlQuery = rewrite("select SUM(msr2) from testCube" + " join citydim on testCube.cityid = citydim.id"
            + " where " + TWO_DAYS_RANGE + " group by name", conf);
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite("select cityid, SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select testcube.cityid," + " sum(testcube.msr2) FROM ", null,
            " group by testcube.cityid ", getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite("select round(cityid), SUM(msr2) from" + " testCube where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select round(testcube.cityid)," + " sum(testcube.msr2) FROM ",
            null, " group by round(testcube.cityid) ",
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite(
            "select SUM(msr2) from testCube" + "  where " + TWO_DAYS_RANGE + "group by round(zipcode)", conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select round(testcube.zipcode)," + " sum(testcube.msr2) FROM ",
            null, " group by round(testcube.zipcode) ",
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite(
            "select round(cityid), SUM(msr2) from" + " testCube where " + TWO_DAYS_RANGE + " group by zipcode",
            conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select " + " round(testcube.cityid), sum(testcube.msr2) FROM ",
            null, " group by testcube.zipcode", getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite("select round(cityid), SUM(msr2) from" + " testCube where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select " + " round(testcube.cityid), sum(testcube.msr2) FROM ",
            null, " group by round(testcube.cityid)",
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite(
            "select cityid, SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE + " group by round(zipcode)",
            conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select " + " testcube.cityid, sum(testcube.msr2) FROM ", null,
            " group by round(testcube.zipcode)", getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite(
            "select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE + " group by round(zipcode)", conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select round(testcube.zipcode)," + " sum(testcube.msr2) FROM ",
            null, " group by round(testcube.zipcode)",
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite(
            "select cityid, msr2 from testCube" + " where " + TWO_DAYS_RANGE + " group by round(zipcode)",
            conf);
    expected = getExpectedQuery(TEST_CUBE_NAME, "select " + " testcube.cityid, sum(testcube.msr2) FROM ", null,
            " group by round(testcube.zipcode)", getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite("select round(zipcode) rzc," + " msr2 from testCube where " + TWO_DAYS_RANGE
            + " group by zipcode" + " order by rzc", conf);
    expected = getExpectedQuery(TEST_CUBE_NAME,
            "select round(testcube.zipcode) as `rzc`," + " sum(testcube.msr2) FROM ", null,
            " group by testcube.zipcode  order by rzc asc",
            getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    //Dim attribute with aggregate function
    hqlQuery = rewrite("select countofdistinctcityid, zipcode from" + " testCube where " + TWO_DAYS_RANGE,
            conf);
    expected = getExpectedQuery(TEST_CUBE_NAME,
            "select " + " count(distinct (testcube.cityid)), (testcube.zipcode) FROM ", null,
            " group by (testcube.zipcode)", getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    //Dim attribute with single row function
    hqlQuery = rewrite("select notnullcityid, zipcode from" + " testCube where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(TEST_CUBE_NAME,
            "select " + " distinct case  when (testcube.cityid) is null then 0 "
                    + "else (testcube.cityid) end, (testcube.zipcode)  FROM ",
            null, "", getWhereForDailyAndHourly2days(TEST_CUBE_NAME, "C2_testfact"));
    compareQueries(hqlQuery, expected);

    // rewrite with expressions
    conf.setBoolean(DISABLE_AUTO_JOINS, false);
    conf.set(DRIVER_SUPPORTED_STORAGES, "C1, C2");
    hqlQuery = rewrite("SELECT cubecity.name AS g1," + " CASE  WHEN cubecity.name=='NULL'  THEN 'NULL' "
            + " WHEN cubecity.name=='X'  THEN 'X-NAME' " + " WHEN cubecity.name=='Y'  THEN 'Y-NAME' "
            + " ELSE 'DEFAULT'   END  AS g2, " + " cubestate.name AS g3," + " cubestate.id AS g4, "
            + " cubezip.code!=1  AND " + " ((cubezip.f1==\"xyz\"  AND  (cubezip.f2 >= \"3\"  AND "
            + "  cubezip.f2 !=\"NULL\"  AND  cubezip.f2 != \"uk\")) "
            + "  OR (cubezip.f2==\"adc\"  AND  cubezip.f1==\"js\" "
            + "  AND  ( cubecity.name == \"X\"  OR  cubecity.name == \"Y\" )) "
            + " OR ((cubezip.f1==\"api\"  OR  cubezip.f1==\"uk\"  OR  (cubezip.f1==\"adc\"  AND  cubezip.f1!=\"js\"))"
            + "  AND  cubecity.id==12) ) AS g5," + " cubezip.code==1  AND "
            + " ((cubezip.f1==\"xyz\"  AND  (cubezip.f2 >= \"3\"  AND "
            + "  cubezip.f2 !=\"NULL\"  AND  cubezip.f2 != \"uk\")) "
            + " OR (cubezip.f2==\"adc\"  AND  cubezip.f1==\"js\" "
            + " AND  ( cubecity.name == \"X\"  OR  cubecity.name == \"Y\" )) "
            + "  OR ((cubezip.f1==\"api\"  OR  cubezip.f1==\"uk\"  OR  (cubezip.f1==\"adc\"  AND  cubezip.f1!=\"js\"))"
            + "    AND  cubecity.id==12) ) AS g6, " + "  cubezip.f1 AS g7, "
            + "  format_number(SUM(msr1),\"##################.###\") AS a1,"
            + "  format_number(SUM(msr2),\"##################.###\") AS a2, "
            + "  format_number(SUM(msr3),\"##################.###\") AS a3, "
            + " format_number(SUM(msr1)+SUM(msr2), \"##################.###\") AS a4,"
            + "  format_number(SUM(msr1)+SUM(msr3),\"##################.###\") AS a5,"
            + " format_number(SUM(msr1)-(SUM(msr2)+SUM(msr3)),\"##################.###\") AS a6"
            + "  FROM testCube where " + TWO_DAYS_RANGE + " HAVING (SUM(msr1) >=1000)  AND (SUM(msr2)>=0.01)",
            conf);
    String actualExpr = "" + " join " + getDbName()
            + "c1_statetable cubestate on testcube.stateid=cubestate.id and " + "(cubestate.dt='latest')"
            + " join " + getDbName()
            + "c1_ziptable cubezip on testcube.zipcode = cubezip.code and (cubezip.dt = 'latest')  " + " join "
            + getDbName()
            + "c1_citytable cubecity on testcube.cityid = cubecity.id and (cubecity.dt = 'latest')" + "";
    expected = getExpectedQuery(TEST_CUBE_NAME, "SELECT ( cubecity.name ) as `g1` ,"
            + "  case  when (( cubecity.name ) ==  'NULL' ) then  'NULL'  when (( cubecity.name ) ==  'X' )"
            + " then  'X-NAME'  when (( cubecity.name ) ==  'Y' ) then  'Y-NAME'"
            + "  else  'DEFAULT'  end  as `g2` , ( cubestate.name ) as `g3` , ( cubestate.id ) as `g4` ,"
            + " ((( cubezip.code ) !=  1 ) and ((((( cubezip.f1 ) ==  \"xyz\" )"
            + " and (((( cubezip.f2 ) >=  \"3\" ) and (( cubezip.f2 ) !=  \"NULL\" ))"
            + " and (( cubezip.f2 ) !=  \"uk\" ))) or (((( cubezip.f2 ) ==  \"adc\" )"
            + " and (( cubezip.f1 ) ==  \"js\" ))"
            + " and ((( cubecity.name ) ==  \"X\" ) or (( cubecity.name ) ==  \"Y\" ))))"
            + " or ((((( cubezip.f1 ) ==  \"api\" )"
            + " or (( cubezip.f1 ) ==  \"uk\" )) or ((( cubezip.f1 ) ==  \"adc\" )"
            + " and (( cubezip.f1 ) !=  \"js\" )))"
            + " and (( cubecity.id ) ==  12 )))) as `g5` , ((( cubezip.code ) ==  1 )"
            + " and ((((( cubezip.f1 ) ==  \"xyz\" ) and (((( cubezip.f2 ) >=  \"3\" )"
            + " and (( cubezip.f2 ) !=  \"NULL\" ))"
            + " and (( cubezip.f2 ) !=  \"uk\" ))) or (((( cubezip.f2 ) ==  \"adc\" )"
            + " and (( cubezip.f1 ) ==  \"js\" ))"
            + " and ((( cubecity.name ) ==  \"X\" ) or (( cubecity.name ) ==  \"Y\" ))))"
            + " or ((((( cubezip.f1 ) ==  \"api\" )"
            + " or (( cubezip.f1 ) ==  \"uk\" )) or ((( cubezip.f1 ) ==  \"adc\" )"
            + " and (( cubezip.f1 ) !=  \"js\" )))"
            + " and (( cubecity.id ) ==  12 )))) as `g6` , ( cubezip.f1 ) as `g7` ,"
            + " format_number(sum(( testcube.msr1 )),  \"##################.###\" ) as `a1` ,"
            + " format_number(sum(( testcube.msr2 )),  \"##################.###\" ) as `a2` ,"
            + " format_number(sum(( testcube.msr3 )),  \"##################.###\" ) as `a3`, "
            + " format_number((sum(( testcube.msr1 )) + sum(( testcube.msr2 ))),  \"##################.###\" ) as `a4` ,"
            + " format_number((sum(( testcube.msr1 )) + sum(( testcube.msr3 ))),  \"##################.###\" ) as `a5` ,"
            + " format_number((sum(( testcube.msr1 )) - (sum(( testcube.msr2 )) + sum(( testcube.msr3 )))), "
            + " \"##################.###\" ) as `a6`" + "  FROM ", actualExpr, null,
            " GROUP BY ( cubecity.name ), case  when (( cubecity.name ) ==  'NULL' ) "
                    + "then  'NULL'  when (( cubecity.name ) ==  'X' ) then  'X-NAME'  when (( cubecity.name ) ==  'Y' )"
                    + " then  'Y-NAME'  else  'DEFAULT'  end, ( cubestate.name ), ( cubestate.id ),"
                    + " ((( cubezip.code ) !=  1 ) and ((((( cubezip.f1 ) ==  \"xyz\" ) and (((( cubezip.f2 ) >=  \"3\" )"
                    + " and (( cubezip.f2 ) !=  \"NULL\" )) and (( cubezip.f2 ) !=  \"uk\" ))) or (((( cubezip.f2 ) ==  \"adc\" )"
                    + " and (( cubezip.f1 ) ==  \"js\" )) and ((( cubecity.name ) ==  \"X\" ) or (( cubecity.name ) ==  \"Y\""
                    + " ))))"
                    + " or ((((( cubezip.f1 ) ==  \"api\" ) or (( cubezip.f1 ) ==  \"uk\" )) or ((( cubezip.f1 ) ==  \"adc\" )"
                    + " and (( cubezip.f1 ) !=  \"js\" ))) and (( cubecity.id ) ==  12 )))), ((( cubezip.code ) ==  1 ) and"
                    + " ((((( cubezip.f1 ) ==  \"xyz\" ) and (((( cubezip.f2 ) >=  \"3\" ) and (( cubezip.f2 ) !=  \"NULL\" ))"
                    + " and (( cubezip.f2 ) !=  \"uk\" ))) or (((( cubezip.f2 ) ==  \"adc\" ) and (( cubezip.f1 ) ==  \"js\" ))"
                    + " and ((( cubecity.name ) ==  \"X\" ) or (( cubecity.name ) ==  \"Y\" )))) or ((((( cubezip.f1 )==\"api\" )"
                    + " or (( cubezip.f1 ) ==  \"uk\" )) or ((( cubezip.f1 ) ==  \"adc\" ) and (( cubezip.f1 ) !=  \"js\" )))"
                    + " and (( cubecity.id ) ==  12 )))), ( cubezip.f1 ) HAVING ((sum(( testcube.msr1 )) >=  1000 ) "
                    + "and (sum(( testcube.msr2 )) >=  0.01 ))",
            null, getWhereForHourly2days("c1_testfact2_raw"));
    compareQueries(hqlQuery, expected);

    hqlQuery = rewrite("SELECT cubecity.name AS g1," + " CASE  WHEN cubecity.name=='NULL'  THEN 'NULL' "
            + " WHEN cubecity.name=='X'  THEN 'X-NAME' " + " WHEN cubecity.name=='Y'  THEN 'Y-NAME' "
            + " ELSE 'DEFAULT'   END  AS g2, " + " cubestate.name AS g3," + " cubestate.id AS g4, "
            + " cubezip.code!=1  AND " + " ((cubezip.f1==\"xyz\"  AND  (cubezip.f2 >= \"3\"  AND "
            + "  cubezip.f2 !=\"NULL\"  AND  cubezip.f2 != \"uk\")) "
            + "  OR (cubezip.f2==\"adc\"  AND  cubezip.f1==\"js\" "
            + "  AND  ( cubecity.name == \"X\"  OR  cubecity.name == \"Y\" )) "
            + " OR ((cubezip.f1==\"api\"  OR  cubezip.f1==\"uk\"  OR  (cubezip.f1==\"adc\"  AND  cubezip.f1!=\"js\"))"
            + "  AND  cubecity.id==12) ) AS g5," + " cubezip.code==1  AND "
            + " ((cubezip.f1==\"xyz\"  AND  (cubezip.f2 >= \"3\"  AND "
            + "  cubezip.f2 !=\"NULL\"  AND  cubezip.f2 != \"uk\")) "
            + " OR (cubezip.f2==\"adc\"  AND  cubezip.f1==\"js\" "
            + " AND  ( cubecity.name == \"X\"  OR  cubecity.name == \"Y\" )) "
            + "  OR ((cubezip.f1==\"api\"  OR  cubezip.f1==\"uk\"  OR  (cubezip.f1==\"adc\"  AND  cubezip.f1!=\"js\"))"
            + "    AND  cubecity.id==12) ) AS g6, " + "  cubezip.f1 AS g7, "
            + "  format_number(SUM(msr1),\"##################.###\") AS a1,"
            + "  format_number(SUM(msr2),\"##################.###\") AS a2, "
            + "  format_number(SUM(msr3),\"##################.###\") AS a3, "
            + " format_number(SUM(msr1)+SUM(msr2), \"##################.###\") AS a4,"
            + "  format_number(SUM(msr1)+SUM(msr3),\"##################.###\") AS a5,"
            + " format_number(SUM(msr1)-(SUM(msr2)+SUM(msr3)),\"##################.###\") AS a6"
            + "  FROM testCube where " + TWO_DAYS_RANGE
            + " group by cubecity.name, CASE WHEN cubecity.name=='NULL' THEN 'NULL'"
            + " WHEN cubecity.name=='X' THEN 'X-NAME' WHEN cubecity.name=='Y' THEN 'Y-NAME'"
            + " ELSE 'DEFAULT'   END, cubestate.name, cubestate.id,  cubezip.code!=1  AND"
            + " ((cubezip.f1==\"xyz\"  AND  (cubezip.f2 >= \"3\"  AND cubezip.f2 !=\"NULL\"  AND  cubezip.f2 != \"uk\"))"
            + " OR (cubezip.f2==\"adc\"  AND  cubezip.f1==\"js\""
            + " AND ( cubecity.name == \"X\"  OR  cubecity.name == \"Y\" ))"
            + " OR ((cubezip.f1==\"api\"  OR  cubezip.f1==\"uk\"  OR  (cubezip.f1==\"adc\"  AND  cubezip.f1!=\"js\"))"
            + " AND  cubecity.id==12) ),"
            + " cubezip.code==1  AND  ((cubezip.f1==\"xyz\" AND ( cubezip.f2 >= \"3\"  AND cubezip.f2 !=\"NULL\""
            + " AND  cubezip.f2 != \"uk\"))" + " OR (cubezip.f2==\"adc\"  AND  cubezip.f1==\"js\""
            + " AND  ( cubecity.name == \"X\"  OR  cubecity.name == \"Y\" ))"
            + " OR ((cubezip.f1=\"api\"  OR  cubezip.f1==\"uk\" OR (cubezip.f1==\"adc\"  AND  cubezip.f1!=\"js\")) AND"
            + " cubecity.id==12))," + " cubezip.f1 " + "HAVING (SUM(msr1) >=1000)  AND (SUM(msr2)>=0.01)",
            conf);
    compareQueries(hqlQuery, expected);
}

From source file:org.apache.lens.cube.parse.TestCubeRewriter.java

License:Apache License

@Test
public void testCubeWhereQueryWithMeasureWithDataCompletenessAndFailIfPartialDataFlagSet()
        throws ParseException, LensException {
    /*In this query a measure is used for which dataCompletenessTag is set and the flag FAIL_QUERY_ON_PARTIAL_DATA is
    set. The partitions for the queried range are present but some of the them have incomplete data. So, the query
    throws NO_CANDIDATE_FACT_AVAILABLE Exception*/
    Configuration conf = getConf();
    conf.setStrings(CubeQueryConfUtil.COMPLETENESS_CHECK_PART_COL, "dt");
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, true);

    LensException e = getLensExceptionInRewrite("select SUM(msr9) from basecube where " + TWO_DAYS_RANGE, conf);
    assertEquals(e.getErrorCode(),/*from   w  w  w  .  j  a  v  a 2 s .c  o  m*/
            LensCubeErrorCode.NO_CANDIDATE_FACT_AVAILABLE.getLensErrorInfo().getErrorCode());
    NoCandidateFactAvailableException ne = (NoCandidateFactAvailableException) e;
    PruneCauses.BriefAndDetailedError pruneCauses = ne.getJsonMessage();
    /*Since the Flag FAIL_QUERY_ON_PARTIAL_DATA is set, and the queried fact has incomplete data, hence, we expect the
    prune cause to be INCOMPLETE_PARTITION. The below check is to validate this.*/
    assertEquals(pruneCauses.getBrief(), String.format(INCOMPLETE_PARTITION.errorFormat, "[msr9]"));
}