Search in sources :

Example 1 with StatsSource

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

the class StatsRulesProcFactory method applyRuntimeStats.

private static Statistics applyRuntimeStats(Context context, Statistics stats, Operator<?> op) {
    if (!((HiveConf) context.getConf()).getBoolVar(ConfVars.HIVE_QUERY_REEXECUTION_ENABLED)) {
        return stats;
    }
    PlanMapper pm = context.getPlanMapper();
    OpTreeSignature treeSig = pm.getSignatureOf(op);
    pm.link(op, treeSig);
    StatsSource statsSource = context.getStatsSource();
    if (!statsSource.canProvideStatsFor(op.getClass())) {
        return stats;
    }
    Optional<OperatorStats> os = statsSource.lookup(treeSig);
    if (!os.isPresent()) {
        return stats;
    }
    LOG.debug("using runtime stats for {}; {}", op, os.get());
    Statistics outStats = stats.clone();
    outStats = outStats.scaleToRowCount(os.get().getOutputRecords(), false);
    outStats.setRuntimeStats(true);
    return outStats;
}
Also used : OpTreeSignature(org.apache.hadoop.hive.ql.optimizer.signature.OpTreeSignature) PlanMapper(org.apache.hadoop.hive.ql.plan.mapper.PlanMapper) OperatorStats(org.apache.hadoop.hive.ql.stats.OperatorStats) Statistics(org.apache.hadoop.hive.ql.plan.Statistics) ColStatistics(org.apache.hadoop.hive.ql.plan.ColStatistics) StatsSource(org.apache.hadoop.hive.ql.plan.mapper.StatsSource)

Example 2 with StatsSource

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

the class HiveRelMdRuntimeRowCount method getRuntimeRowCount.

public Optional<Long> getRuntimeRowCount(RelNode rel) {
    RelOptCluster cluster = rel.getCluster();
    Context context = cluster.getPlanner().getContext();
    if (context instanceof HivePlannerContext) {
        StatsSource ss = ((HivePlannerContext) context).unwrap(StatsSource.class);
        if (ss.canProvideStatsFor(rel.getClass())) {
            Optional<OperatorStats> os = ss.lookup(RelTreeSignature.of(rel));
            if (os.isPresent()) {
                long outputRecords = os.get().getOutputRecords();
                return Optional.of(outputRecords);
            }
        }
    }
    return Optional.empty();
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) Context(org.apache.calcite.plan.Context) HivePlannerContext(org.apache.hadoop.hive.ql.optimizer.calcite.HivePlannerContext) HivePlannerContext(org.apache.hadoop.hive.ql.optimizer.calcite.HivePlannerContext) OperatorStats(org.apache.hadoop.hive.ql.stats.OperatorStats) StatsSource(org.apache.hadoop.hive.ql.plan.mapper.StatsSource)

Aggregations

StatsSource (org.apache.hadoop.hive.ql.plan.mapper.StatsSource)2 OperatorStats (org.apache.hadoop.hive.ql.stats.OperatorStats)2 Context (org.apache.calcite.plan.Context)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 HivePlannerContext (org.apache.hadoop.hive.ql.optimizer.calcite.HivePlannerContext)1 OpTreeSignature (org.apache.hadoop.hive.ql.optimizer.signature.OpTreeSignature)1 ColStatistics (org.apache.hadoop.hive.ql.plan.ColStatistics)1 Statistics (org.apache.hadoop.hive.ql.plan.Statistics)1 PlanMapper (org.apache.hadoop.hive.ql.plan.mapper.PlanMapper)1