Search in sources :

Example 11 with TezCounters

use of org.apache.tez.common.counters.TezCounters in project hive by apache.

the class OperatorStatsReaderHook method run.

@Override
public void run(HookContext hookContext) throws Exception {
    if (hookContext.getHookType() == HookType.PRE_EXEC_HOOK) {
        return;
    }
    if (hookContext.getHookType() == HookType.POST_EXEC_HOOK && !isCollectOnSuccess()) {
        return;
    }
    HiveConf conf = hookContext.getConf();
    QueryPlan plan = hookContext.getQueryPlan();
    List<TezTask> rootTasks = Utilities.getTezTasks(plan.getRootTasks());
    for (TezTask tezTask : rootTasks) {
        List<BaseWork> baseWorks = tezTask.getWork().getAllWork();
        for (BaseWork baseWork : baseWorks) {
            String vertexName = baseWork.getName();
            LOG.debug("Reading runtime statistics for tez vertex task: {}", vertexName);
            TezCounters counters = tezTask.getTezCounters();
            if (counters != null) {
                String groupName = HiveConf.getVar(conf, HiveConf.ConfVars.HIVECOUNTERGROUP);
                for (Operator<? extends OperatorDesc> op : baseWork.getAllOperators()) {
                    String operatorId = op.getOperatorId();
                    OperatorStats operatorStats = null;
                    String counterName = Operator.Counter.RECORDS_OUT_OPERATOR.toString() + "_" + operatorId;
                    TezCounter tezCounter = counters.getGroup(groupName).findCounter(counterName, false);
                    if (tezCounter != null) {
                        if (operatorStats == null) {
                            operatorStats = new OperatorStats(operatorId);
                        }
                        operatorStats.setOutputRecords(tezCounter.getValue());
                    }
                    if (operatorStats != null) {
                        ((PrivateHookContext) hookContext).getContext().getPlanMapper().link(op, operatorStats);
                    } else {
                        LOG.debug("Unable to get statistics for vertex: {} opId: {} groupName: {}", vertexName, operatorId, groupName);
                    }
                }
            }
        }
    }
}
Also used : HiveConf(org.apache.hadoop.hive.conf.HiveConf) TezCounter(org.apache.tez.common.counters.TezCounter) QueryPlan(org.apache.hadoop.hive.ql.QueryPlan) PrivateHookContext(org.apache.hadoop.hive.ql.hooks.PrivateHookContext) TezTask(org.apache.hadoop.hive.ql.exec.tez.TezTask) BaseWork(org.apache.hadoop.hive.ql.plan.BaseWork) TezCounters(org.apache.tez.common.counters.TezCounters)

Aggregations

TezCounters (org.apache.tez.common.counters.TezCounters)11 TezCounter (org.apache.tez.common.counters.TezCounter)5 StatusGetOpts (org.apache.tez.dag.api.client.StatusGetOpts)5 HiveConf (org.apache.hadoop.hive.conf.HiveConf)4 QueryPlan (org.apache.hadoop.hive.ql.QueryPlan)3 TezTask (org.apache.hadoop.hive.ql.exec.tez.TezTask)3 SessionState (org.apache.hadoop.hive.ql.session.SessionState)3 CounterGroup (org.apache.tez.common.counters.CounterGroup)3 List (java.util.List)2 BaseWork (org.apache.hadoop.hive.ql.plan.BaseWork)2 Preconditions (com.google.common.base.Preconditions)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 StringWriter (java.io.StringWriter)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1