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.FieldsCannotBeQueriedTogetherTest.java

License:Apache License

@Test
public void testQueryWtihTimeDimAndReplaceTimeDimSwitchTrue() throws ParseException, LensException {

    /* If a time dimension and measure are not present in the same derived cube, then query shall be disallowed.
            //from www.  j  a v a2s.c om
    The testQuery in this test uses d_time in time range func. d_time is a time dimension in basecube.
    d_time is present as a dimension in derived cube where as msr4 is not present in the same derived cube, hence
    the query shall be disallowed.
            
    The testQuery in this test uses its own queryConf which has CubeQueryConfUtil.REPLACE_TIMEDIM_WITH_PART_COL
    set to true. */

    Configuration queryConf = new Configuration(conf);
    queryConf.setBoolean(CubeQueryConfUtil.REPLACE_TIMEDIM_WITH_PART_COL, true);

    testFieldsCannotBeQueriedTogetherError("select msr4 from basecube where " + TWO_DAYS_RANGE,
            Arrays.asList("d_time", "msr4"), queryConf);
}

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

License:Apache License

@Test
public void testQueryWtihTimeDimAndReplaceTimeDimSwitchFalse() throws ParseException, LensException {

    /* If a time dimension and measure are not present in the same derived cube, then query shall be disallowed.
            /*  w  w w  . java 2s  .  c o  m*/
    The testQuery in this test uses d_time in time range func. d_time is a time dimension in basecube.
    d_time is present as a dimension in derived cube where as msr4 is not present in the same derived cube, hence
    the query shall be disallowed.
            
    The testQuery in this test uses its own queryConf which has CubeQueryConfUtil.REPLACE_TIMEDIM_WITH_PART_COL
    set to false */

    Configuration queryConf = new Configuration(conf);
    queryConf.setBoolean(CubeQueryConfUtil.REPLACE_TIMEDIM_WITH_PART_COL, false);

    testFieldsCannotBeQueriedTogetherError("select msr4 from basecube where " + TWO_DAYS_RANGE,
            Arrays.asList("d_time", "msr4"), queryConf);
}

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

License:Apache License

@Test
public void testAggregateResolverOff() throws ParseException, LensException {
    Configuration conf2 = getConfWithStorages("C1,C2");
    conf2.setBoolean(CubeQueryConfUtil.DISABLE_AGGREGATE_RESOLVER, true);

    // Test if raw fact is selected for query with no aggregate function on a
    // measure, with aggregate resolver disabled
    String query = "SELECT cityid, testCube.msr2 FROM testCube WHERE " + TWO_DAYS_RANGE;
    CubeQueryContext cubeql = rewriteCtx(query, conf2);
    String hQL = cubeql.toHQL();/*from  www .j  a  v  a  2s. co  m*/
    Assert.assertEquals(1, cubeql.getCandidateFacts().size());
    CandidateFact candidateFact = cubeql.getCandidateFacts().iterator().next();
    Assert.assertEquals("testFact2_raw".toLowerCase(), candidateFact.fact.getName().toLowerCase());
    String expectedQL = getExpectedQuery(cubeName, "SELECT testcube.cityid, testCube.msr2 from ", null, null,
            getWhereForHourly2days("c1_testfact2_raw"));
    compareQueries(hQL, expectedQL);
    conf2.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C2");
    aggregateFactSelectionTests(conf2);
    conf2.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C1,C2");
    rawFactSelectionTests(conf2);
}

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

License:Apache License

@Test
public void testMultiFactQueryWithSingleCommonDimensionWithLightestFactFirst() throws Exception {
    Configuration tConf = new Configuration(conf);
    tConf.setBoolean(CubeQueryConfUtil.LIGHTEST_FACT_FIRST, true);
    String hqlQuery = rewrite("select dim1, roundedmsr2, msr12 from basecube" + " where " + TWO_DAYS_RANGE,
            tConf);/*w ww  .java2  s  .c om*/
    String expected1 = getExpectedQuery(cubeName,
            "select basecube.dim1 as `dim1`, sum(basecube.msr12) as `msr12` FROM ", null,
            " group by basecube.dim1", getWhereForDailyAndHourly2days(cubeName, "C1_testFact2_BASE"));
    String expected2 = getExpectedQuery(cubeName,
            "select basecube.dim1 as `dim1`, round(sum(basecube.msr2)/1000) as `roundedmsr2` FROM ", null,
            " group by basecube.dim1", getWhereForDailyAndHourly2days(cubeName, "C1_testFact1_BASE"));
    compareContains(expected1, hqlQuery);
    compareContains(expected2, hqlQuery);
    String lower = hqlQuery.toLowerCase();
    assertTrue(lower.startsWith(
            "select coalesce(mq1.dim1, mq2.dim1) dim1, mq2.roundedmsr2 roundedmsr2, mq1.msr12 msr12 from ")
            || lower.startsWith(
                    "select coalesce(mq1.dim1, mq2.dim1) dim1, mq1.roundedmsr2 roundedmsr2, mq2.msr12 msr12"
                            + " from "),
            hqlQuery);

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

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

License:Apache License

@Test
public void testMultiFactQueryWithExpressionsFromMultipleFacts() throws Exception {
    Configuration tConf = new Configuration(conf);
    tConf.setBoolean(CubeQueryConfUtil.LIGHTEST_FACT_FIRST, true);
    String hqlQuery = rewrite(/* ww w  .j  a va2s  .c o m*/
            "select  dim1, roundedmsr2, flooredmsr12 from basecube" + " where " + TWO_DAYS_RANGE, tConf);
    String expected1 = getExpectedQuery(cubeName,
            "select basecube.dim1 as `dim1`, " + "floor(sum(( basecube . msr12 ))) as `flooredmsr12` FROM ",
            null, " group by basecube.dim1", getWhereForDailyAndHourly2days(cubeName, "C1_testFact2_BASE"));
    String expected2 = getExpectedQuery(cubeName,
            "select basecube.dim1 as `dim1`, round(sum(basecube.msr2)/1000) as `roundedmsr2` FROM ", null,
            " group by basecube.dim1", getWhereForDailyAndHourly2days(cubeName, "C1_testFact1_BASE"));
    compareContains(expected1, hqlQuery);
    compareContains(expected2, hqlQuery);
    String lower = hqlQuery.toLowerCase();
    assertTrue(lower
            .startsWith("select coalesce(mq1.dim1, mq2.dim1) dim1, mq2.roundedmsr2 roundedmsr2, "
                    + "mq1.flooredmsr12 flooredmsr12 from ")
            || lower.startsWith("select coalesce(mq1.dim1, mq2.dim1) dim1, mq1.roundedmsr2 roundedmsr2, "
                    + "mq2.flooredmsr12 flooredmsr12" + " from "),
            hqlQuery);

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

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

License:Apache License

@Test
public void testFallbackPartCol() throws Exception {
    Configuration conf = getConfWithStorages("C1");
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false);
    String hql, expected;/*from w w  w . ja v  a2 s .com*/
    // Prefer fact that has a storage with part col on queried time dim
    hql = rewrite("select msr12 from basecube where " + TWO_DAYS_RANGE, conf);
    expected = getExpectedQuery(BASE_CUBE_NAME, "select sum(basecube.msr12) FROM ", null, null,
            getWhereForDailyAndHourly2days(BASE_CUBE_NAME, "c1_testfact2_base"));
    compareQueries(hql, expected);

    // If going to fallback timedim, and partitions are missing, then error should be missing partition on that
    conf.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C4");
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, true);
    LensException exc = getLensExceptionInRewrite("select msr12 from basecube where " + TWO_DAYS_RANGE, conf);
    NoCandidateFactAvailableException ne = (NoCandidateFactAvailableException) exc;
    PruneCauses.BriefAndDetailedError pruneCause = ne.getJsonMessage();
    assertTrue(pruneCause.getBrief().contains("Missing partitions"));
    assertEquals(pruneCause.getDetails().get("testfact2_base").iterator().next().getCause(),
            MISSING_PARTITIONS);
    assertEquals(pruneCause.getDetails().get("testfact2_base").iterator().next().getMissingPartitions().size(),
            1);
    assertEquals(
            pruneCause.getDetails().get("testfact2_base").iterator().next().getMissingPartitions().iterator()
                    .next(),
            "ttd:[" + UpdatePeriod.SECONDLY
                    .format(DateUtils.addDays(DateUtils.truncate(TWODAYS_BACK, Calendar.HOUR), -10)) + ", "
                    + UpdatePeriod.SECONDLY
                            .format(DateUtils.addDays(DateUtils.truncate(NOW, Calendar.HOUR), 10))
                    + ")");

    // fail on partial false. Should go to fallback column. Also testing transitivity of timedim relations
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false);
    hql = rewrite("select msr12 from basecube where " + TWO_DAYS_RANGE, conf);
    String dTimeWhereClause = "basecube.d_time >= '"
            + HIVE_QUERY_DATE_PARSER.get()
                    .format(ABSDATE_PARSER.get().parse(getAbsDateFormatString(getDateUptoHours(TWODAYS_BACK))))
            + "' and " + "basecube.d_time < '" + HIVE_QUERY_DATE_PARSER.get()
                    .format(ABSDATE_PARSER.get().parse(getAbsDateFormatString(getDateUptoHours(NOW))));
    String pTimeWhereClause = "basecube.processing_time >= '"
            + HIVE_QUERY_DATE_PARSER.get()
                    .format(ABSDATE_PARSER.get().parse(
                            getAbsDateFormatString(getDateUptoHours(DateUtils.addDays(TWODAYS_BACK, -5)))))
            + "' and " + "basecube.processing_time < '" + HIVE_QUERY_DATE_PARSER.get().format(ABSDATE_PARSER
                    .get().parse(getAbsDateFormatString(getDateUptoHours(DateUtils.addDays(NOW, 5)))));
    expected = getExpectedQuery(BASE_CUBE_NAME, "select sum(basecube.msr12) FROM ", null,
            " and " + dTimeWhereClause + " and " + pTimeWhereClause,
            getWhereForDailyAndHourly2daysWithTimeDim(BASE_CUBE_NAME, "ttd",
                    DateUtils.addDays(TWODAYS_BACK, -10), DateUtils.addDays(NOW, 10), "c4_testfact2_base"));
    compareQueries(hql, expected);

    // Multiple timedims in single query. test that
    CubeQueryContext ctx = rewriteCtx(
            "select msr12 from basecube where " + TWO_DAYS_RANGE + " and " + TWO_DAYS_RANGE_TTD, conf);
    assertEquals(ctx.getCandidateFactSets().size(), 1);
    assertEquals(ctx.getCandidateFactSets().iterator().next().size(), 1);
    CandidateFact cfact = ctx.getCandidateFactSets().iterator().next().iterator().next();

    assertEquals(cfact.getRangeToStoragePartMap().size(), 2);
    Set<String> storages = Sets.newHashSet();
    for (Map<String, String> entry : cfact.getRangeToStorageWhereMap().values()) {
        storages.addAll(entry.keySet());
    }
    assertEquals(storages.size(), 1);
    String storage = storages.iterator().next();
    for (Map.Entry<TimeRange, Map<String, String>> entry : cfact.getRangeToStorageWhereMap().entrySet()) {
        if (entry.getKey().getPartitionColumn().equals("dt")) {
            ASTNode parsed = HQLParser.parseExpr(entry.getValue().get(storage));
            assertEquals(parsed.getToken().getType(), KW_AND);
            assertTrue(entry.getValue().get(storage)
                    .substring(((CommonToken) parsed.getToken()).getStopIndex() + 1).toLowerCase()
                    .contains(dTimeWhereClause));
            assertFalse(entry.getValue().get(storage)
                    .substring(0, ((CommonToken) parsed.getToken()).getStartIndex()).toLowerCase()
                    .contains("and"));
        } else if (entry.getKey().getPartitionColumn().equals("ttd")) {
            assertFalse(entry.getValue().get(storage).toLowerCase().contains("and"));
        } else {
            throw new LensException("Unexpected");
        }
    }
}

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

License:Apache License

@Test
public void testFlattenBridgeTablesOFF() throws Exception {
    Configuration conf = new Configuration(hConf);
    conf.setBoolean(CubeQueryConfUtil.ENABLE_FLATTENING_FOR_BRIDGETABLES, false);
    String query = "select usersports.name, sum(msr2) from basecube where " + TWO_DAYS_RANGE;
    String hqlQuery = rewrite(query, conf);
    String expected = getExpectedQuery("basecube", "select usersports.name, sum(basecube.msr2) FROM ",
            " join " + getDbName() + "c1_usertable userdim ON basecube.userid = userdim.id " + " join "
                    + getDbName()/* w  w  w .j  a v a  2  s.c o  m*/
                    + "c1_user_interests_tbl user_interests on userdim.id = user_interests.user_id" + " join "
                    + getDbName() + "c1_sports_tbl usersports on user_interests.sport_id = usersports.id",
            null, "group by usersports.name", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact1_base"));
    TestCubeRewriter.compareQueries(hqlQuery, expected);
    // run with chain ref column
    query = "select sports, sum(msr2) from basecube where " + TWO_DAYS_RANGE;
    hqlQuery = rewrite(query, conf);
    TestCubeRewriter.compareQueries(hqlQuery, expected);
}

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

License:Apache License

@Test
public void testBridgeTablesWithFilterAfterFlattening() throws Exception {
    Configuration conf = new Configuration(hConf);
    conf.setBoolean(CubeQueryConfUtil.DO_FLATTENING_OF_BRIDGE_TABLE_EARLY, true);
    String query = "select usersports.name, 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, 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, " and usersports.name = 'CRICKET,FOOTBALL' group by usersports.name", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact1_base"));
    TestCubeRewriter.compareQueries(hqlQuery, expected);
    // run with chain ref column
    query = "select sports, sum(msr2) from basecube where " + TWO_DAYS_RANGE
            + " and sports = 'CRICKET,FOOTBALL'";
    hqlQuery = rewrite(query, conf);//from   ww w.  j  ava 2s.  c o m
    TestCubeRewriter.compareQueries(hqlQuery, expected);
}

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

License:Apache License

@Test
public void testBridgeTablesWithMultipleFactsWithFilterAfterFlattening() throws Exception {
    Configuration conf = new Configuration(hConf);
    conf.setBoolean(CubeQueryConfUtil.DO_FLATTENING_OF_BRIDGE_TABLE_EARLY, true);
    String query = "select usersports.name, msr2, msr12 from basecube where " + TWO_DAYS_RANGE
            + " and usersports.name = 'CRICKET,FOOTBALL'";
    String hqlQuery = rewrite(query, conf);
    String expected1 = getExpectedQuery("basecube",
            "select usersports.name as `name`, 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 usersports.name", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact1_base"));
    String expected2 = getExpectedQuery("basecube",
            "select usersports.name as `name`, 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 usersports.name", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact2_base"));
    TestCubeRewriter.compareContains(expected1, hqlQuery);
    TestCubeRewriter.compareContains(expected2, hqlQuery);
    String lower = hqlQuery.toLowerCase();
    assertTrue(//from   w  w w.  ja  v  a  2  s  .co  m
            lower.startsWith("select coalesce(mq1.name, mq2.name) name, mq2.msr2 msr2, mq1.msr12 msr12 from ")
                    || lower.startsWith(
                            "select coalesce(mq1.name, mq2.name) name, mq1.msr2 msr2, mq2.msr12 msr12 from "),
            hqlQuery);

    assertTrue(hqlQuery.contains("mq1 full outer join ") && hqlQuery.endsWith("mq2 on mq1.name <=> mq2.name"),
            hqlQuery);
    // run with chain ref column
    query = "select sports, msr2, msr12 from basecube where " + TWO_DAYS_RANGE
            + " and sports = 'CRICKET,FOOTBALL'";
    hqlQuery = rewrite(query, conf);
    expected1 = getExpectedQuery("basecube",
            "select usersports.name as `sports`, 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 usersports.name", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact1_base"));
    expected2 = getExpectedQuery("basecube",
            "select usersports.name as `sports`, 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 usersports.name", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact2_base"));
    TestCubeRewriter.compareContains(expected1, hqlQuery);
    TestCubeRewriter.compareContains(expected2, hqlQuery);
    lower = hqlQuery.toLowerCase();
    assertTrue(lower
            .startsWith("select coalesce(mq1.sports, mq2.sports) sports, mq2.msr2 msr2, mq1.msr12 msr12 from ")
            || lower.startsWith(
                    "select coalesce(mq1.sports, mq2.sports) sports, mq1.msr2 msr2, mq2.msr12 msr12 from "),
            hqlQuery);

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

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

License:Apache License

@Test
public void testBridgeTablesWithExpressionAfterFlattening() throws Exception {
    Configuration conf = new Configuration(hConf);
    conf.setBoolean(CubeQueryConfUtil.DO_FLATTENING_OF_BRIDGE_TABLE_EARLY, true);
    String query = "select substr(usersports.name, 3), sum(msr2) from basecube where " + TWO_DAYS_RANGE
            + " and usersports.name = 'CRICKET,FOOTBALL'";
    String hqlQuery = rewrite(query, conf);
    String expected = getExpectedQuery("basecube",
            "select substr(usersports.name, 3), 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, " and usersports.name = 'CRICKET,FOOTBALL' group by substr(usersports.name, 3)", null,
            getWhereForDailyAndHourly2days("basecube", "c1_testfact1_base"));
    TestCubeRewriter.compareQueries(hqlQuery, expected);
    // run with chain ref column
    query = "select sports_abbr, sum(msr2) from basecube where " + TWO_DAYS_RANGE
            + " and sports = 'CRICKET,FOOTBALL'";
    hqlQuery = rewrite(query, conf);/*from w  w w  .j  ava 2 s . co  m*/
    TestCubeRewriter.compareQueries(hqlQuery, expected);
}