public static String getExplainOutput(BaseSemanticAnalyzer sem, QueryPlan plan, ASTNode astTree,
      QueryState queryState, Context context, HiveConf conf) throws IOException {
    String ret = null;
    ExplainTask task = new ExplainTask();
    task.initialize(queryState, plan, null, context);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    try {
      List<Task<?>> rootTasks = sem.getAllRootTasks();
      boolean isExtended = conf.getBoolVar(ConfVars.HIVE_LOG_EXPLAIN_OUTPUT_INCLUDE_EXTENDED);
      if (conf.getBoolVar(ConfVars.HIVE_SERVER2_WEBUI_SHOW_GRAPH)) {
        JSONObject jsonPlan = task.getJSONPlan(
            null, rootTasks, sem.getFetchTask(), true, isExtended, true, sem.getCboInfo(),
            plan.getOptimizedCBOPlan(), plan.getOptimizedQueryString());
        if (jsonPlan.getJSONObject(ExplainTask.STAGE_DEPENDENCIES) != null &&
            jsonPlan.getJSONObject(ExplainTask.STAGE_DEPENDENCIES).length() <=
                conf.getIntVar(ConfVars.HIVE_SERVER2_WEBUI_MAX_GRAPH_SIZE)) {
          ret = jsonPlan.toString();
        } else {
          ret = null;
        }
      } else {
        task.getJSONPlan(ps, rootTasks, sem.getFetchTask(), false, isExtended, true, sem.getCboInfo(),
            plan.getOptimizedCBOPlan(), plan.getOptimizedQueryString());
        ret = baos.toString();
      }
    } catch (Exception e) {
      LOG.warn("Exception generating explain output: " + e, e);
    }

    return ret;
  }
Returns EXPLAIN EXTENDED output for a semantically analyzed query.

@param sem semantic analyzer for analyzed query
@param plan query plan
@param astTree AST tree dump
ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java