@Override
  public void run(HookContext hookContext) throws Exception {
    assert (hookContext.getHookType() == HookContext.HookType.POST_EXEC_HOOK);
    HiveConf conf = hookContext.getConf();
    if (!"tez".equals(HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_EXECUTION_ENGINE))) {
      return;
    }

    LOG.info("Executing post execution hook to print tez summary..");
    SessionState ss = SessionState.get();
    SessionState.LogHelper console = ss.getConsole();
    QueryPlan plan = hookContext.getQueryPlan();
    if (plan == null) {
      return;
    }

    List<TezTask> rootTasks = Utilities.getTezTasks(plan.getRootTasks());
    for (TezTask tezTask : rootTasks) {
      LOG.info("Printing summary for tez task: " + tezTask.getName());
      TezCounters counters = tezTask.getTezCounters();
      if (counters != null) {
        String hiveCountersGroup = HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_COUNTER_GROUP);
        for (CounterGroup group : counters) {
          if (hiveCountersGroup.equals(group.getDisplayName())) {
            console.printInfo(tezTask.getId() + " HIVE COUNTERS:", false);
            for (TezCounter counter : group) {
              // HIVE Counter names are picked at runtime so cannot rely on testSafeCounterNames like in LlapIOCounters
              // Here we just filter out time counters (like HASHTABLE_LOAD_TIME_MS) that may differ across runs
              if (!counter.getName().contains("TIME")) {
                console.printInfo("   " + counter.getDisplayName() + ": " + counter.getValue(), false);
              }
            }
          }  else if (group.getName().equals(HiveInputCounters.class.getName())) {
            console.printInfo(tezTask.getId() + " INPUT COUNTERS:", false);
            for (TezCounter counter : group) {
              console.printInfo("   " + counter.getDisplayName() + ": " + counter.getValue(), false);
            }
          } else if (group.getName().equals(FileSystemCounter.class.getName())) {
            console.printInfo(tezTask.getId() + " FILE SYSTEM COUNTERS:", false);
            for (TezCounter counter : group) {
              // HDFS counters should be relatively consistent across test runs when compared to
              // local file system counters
              if (counter.getName().contains("HDFS")) {
                console.printInfo("   " + counter.getDisplayName() + ": " + counter.getValue(), false);
              }
            }
          } else if (group.getName().equals(LlapIOCounters.class.getName())) {
            console.printInfo(tezTask.getId() + " LLAP IO COUNTERS:", false);
            List<String> testSafeCounters = LlapIOCounters.testSafeCounterNames();
            for (TezCounter counter : group) {
              if (testSafeCounters.contains(counter.getDisplayName())) {
                console.printInfo("   " + counter.getDisplayName() + ": " + counter.getValue(), false);
              }
            }
          } else if (group.getName().equals(CompileTimeCounters.class.getName())) {
            console.printInfo(tezTask.getId() + " COMPILE TIME COUNTERS:", false);
            for (TezCounter counter : group) {
              console.printInfo("   " + counter.getDisplayName() + ": " + counter.getValue(), false);
            }
          }
        }
      }
    }
  }
Post execution hook to print hive tez counters to console error stream.
ql/src/java/org/apache/hadoop/hive/ql/hooks/PostExecTezSummaryPrinter.java