Search in sources :

Example 21 with PlanMapper

use of org.apache.hadoop.hive.ql.plan.mapper.PlanMapper in project hive by apache.

the class TestCounterMapping method getMapperForQuery.

private PlanMapper getMapperForQuery(IDriver driver, String query) throws CommandProcessorException {
    driver.run(query);
    PlanMapper pm0 = driver.getContext().getPlanMapper();
    return pm0;
}
Also used : PlanMapper(org.apache.hadoop.hive.ql.plan.mapper.PlanMapper)

Example 22 with PlanMapper

use of org.apache.hadoop.hive.ql.plan.mapper.PlanMapper in project hive by apache.

the class TestCounterMapping method testUsageOfRuntimeInfo.

@Test
public void testUsageOfRuntimeInfo() throws ParseException, CommandProcessorException {
    IDriver driver = createDriver();
    String query = "select sum(u) from tu where u>1";
    PlanMapper pm1 = getMapperForQuery(driver, query);
    List<FilterOperator> filters1 = pm1.getAll(FilterOperator.class);
    filters1.sort(OPERATOR_ID_COMPARATOR.reversed());
    FilterOperator filter1 = filters1.get(0);
    driver = createDriver();
    ((ReExecDriver) driver).setStatsSource(StatsSources.getStatsSourceContaining(EmptyStatsSource.INSTANCE, pm1));
    PlanMapper pm2 = getMapperForQuery(driver, query);
    List<FilterOperator> filters2 = pm2.getAll(FilterOperator.class);
    filters2.sort(OPERATOR_ID_COMPARATOR.reversed());
    FilterOperator filter2 = filters2.get(0);
    assertEquals("original check", 7, filter1.getStatistics().getNumRows());
    assertEquals("optimized check", 6, filter2.getStatistics().getNumRows());
}
Also used : FilterOperator(org.apache.hadoop.hive.ql.exec.FilterOperator) PlanMapper(org.apache.hadoop.hive.ql.plan.mapper.PlanMapper) IDriver(org.apache.hadoop.hive.ql.IDriver) ReExecDriver(org.apache.hadoop.hive.ql.reexec.ReExecDriver) Test(org.junit.Test)

Example 23 with PlanMapper

use of org.apache.hadoop.hive.ql.plan.mapper.PlanMapper in project hive by apache.

the class TestCounterMapping method testBreakupAnd.

@Test
public void testBreakupAnd() throws ParseException, CommandProcessorException {
    String query = "explain select sum(id_uv) from tu where u=1  and (u=2 or u=1) group by u";
    IDriver driver = createDriver();
    PlanMapper pm = getMapperForQuery(driver, query);
    List<FilterOperator> fos = pm.getAll(FilterOperator.class);
    OpTreeSignature filterSig = pm.lookup(OpTreeSignature.class, fos.get(0));
    Object pred = filterSig.getSig().getSigMap().get("getPredicateString");
    assertEquals("(u = 1) (type: boolean)", pred);
}
Also used : FilterOperator(org.apache.hadoop.hive.ql.exec.FilterOperator) OpTreeSignature(org.apache.hadoop.hive.ql.optimizer.signature.OpTreeSignature) PlanMapper(org.apache.hadoop.hive.ql.plan.mapper.PlanMapper) IDriver(org.apache.hadoop.hive.ql.IDriver) Test(org.junit.Test)

Example 24 with PlanMapper

use of org.apache.hadoop.hive.ql.plan.mapper.PlanMapper in project hive by apache.

the class TestReOptimization method testReOptimizationCanSendBackStatsToCBO.

@Test
public void testReOptimizationCanSendBackStatsToCBO() throws Exception {
    IDriver driver = createDriver("overlay,reoptimize");
    // @formatter:off
    String query = "select assert_true_oom(${hiveconf:zzz} > sum(u*v*w)) from tu\n" + "        join tv on (tu.id_uv=tv.id_uv)\n" + "        join tw on (tu.id_uw=tw.id_uw)\n" + "        where w>9 and u>1 and v>3";
    // @formatter:on
    PlanMapper pm = getMapperForQuery(driver, query);
    Iterator<EquivGroup> itG = pm.iterateGroups();
    int checkedOperators = 0;
    while (itG.hasNext()) {
        EquivGroup g = itG.next();
        List<FilterOperator> fos = g.getAll(FilterOperator.class);
        List<OperatorStats> oss = g.getAll(OperatorStats.class);
        List<HiveFilter> hfs = g.getAll(HiveFilter.class);
        if (fos.size() > 0 && oss.size() > 0 && hfs.size() > 0) {
            fos.sort(TestCounterMapping.OPERATOR_ID_COMPARATOR.reversed());
            HiveFilter hf = hfs.get(0);
            FilterOperator fo = fos.get(0);
            OperatorStats os = oss.get(0);
            long cntFilter = RelMetadataQuery.instance().getRowCount(hf).longValue();
            if (fo.getStatistics() != null) {
            // in case the join order is changed the subTree-s are not matching anymore because an RS is present in the condition
            // assertEquals(os.getOutputRecords(), fo.getStatistics().getNumRows());
            }
            assertEquals(os.getOutputRecords(), cntFilter);
            checkedOperators++;
        }
    }
    assertEquals(3, checkedOperators);
}
Also used : PlanMapper(org.apache.hadoop.hive.ql.plan.mapper.PlanMapper) OperatorStats(org.apache.hadoop.hive.ql.stats.OperatorStats) HiveFilter(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter) FilterOperator(org.apache.hadoop.hive.ql.exec.FilterOperator) IDriver(org.apache.hadoop.hive.ql.IDriver) EquivGroup(org.apache.hadoop.hive.ql.plan.mapper.PlanMapper.EquivGroup) Test(org.junit.Test)

Example 25 with PlanMapper

use of org.apache.hadoop.hive.ql.plan.mapper.PlanMapper in project hive by apache.

the class TestStatEstimations method testFilterStringIn.

@Test
public void testFilterStringIn() throws ParseException, CommandProcessorException {
    IDriver driver = createDriver();
    String query = "explain select a from t2 where b IN ('A3', 'ABC', 'AXZ') order by a";
    PlanMapper pm = getMapperForQuery(driver, query);
    List<FilterOperator> fos = pm.getAll(FilterOperator.class);
    // the same operator is present 2 times
    fos.sort(TestCounterMapping.OPERATOR_ID_COMPARATOR.reversed());
    FilterOperator fop = fos.get(0);
    // any estimation near 1 is ok...currently 1
    assertEquals(1, fop.getStatistics().getNumRows());
}
Also used : FilterOperator(org.apache.hadoop.hive.ql.exec.FilterOperator) PlanMapper(org.apache.hadoop.hive.ql.plan.mapper.PlanMapper) IDriver(org.apache.hadoop.hive.ql.IDriver) Test(org.junit.Test)

Aggregations

PlanMapper (org.apache.hadoop.hive.ql.plan.mapper.PlanMapper)26 IDriver (org.apache.hadoop.hive.ql.IDriver)17 Test (org.junit.Test)17 FilterOperator (org.apache.hadoop.hive.ql.exec.FilterOperator)12 OpTreeSignature (org.apache.hadoop.hive.ql.optimizer.signature.OpTreeSignature)5 OperatorStats (org.apache.hadoop.hive.ql.stats.OperatorStats)4 Statistics (org.apache.hadoop.hive.ql.plan.Statistics)3 EquivGroup (org.apache.hadoop.hive.ql.plan.mapper.PlanMapper.EquivGroup)3 HiveFilter (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter)2 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)2 Ignore (org.junit.Ignore)2 IOException (java.io.IOException)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 CommonJoinOperator (org.apache.hadoop.hive.ql.exec.CommonJoinOperator)1 ColStatistics (org.apache.hadoop.hive.ql.plan.ColStatistics)1 SimpleRuntimeStatsSource (org.apache.hadoop.hive.ql.plan.mapper.SimpleRuntimeStatsSource)1 StatsSource (org.apache.hadoop.hive.ql.plan.mapper.StatsSource)1 CommandProcessorException (org.apache.hadoop.hive.ql.processors.CommandProcessorException)1 ReExecDriver (org.apache.hadoop.hive.ql.reexec.ReExecDriver)1