private void enrichFromRuntimeContext(TezRuntimeContext runtimeContext, Record record) {
    // null in case of HS2-only queries (no Tez involved)
    // dagId null-check is for safety's sake when TezTask was initialized (so a plan was generated) but no DAG ran
    if (runtimeContext == null || runtimeContext.getDagId() == null) {
      setInvalidValuesForRuntimeFields(record);
      return;
    }

    record.setExecutionMode(runtimeContext.getExecutionMode());
    record.setDagId(runtimeContext.getDagId());
    record.setTezApplicationId(runtimeContext.getApplicationId());
    record.setTezSessionId(runtimeContext.getSessionId());
    record.setTezAmAddress(runtimeContext.getAmAddress());
    record.setExecSummary(runtimeContext.getMonitor().logger().getQuerySummary());
    record.setTotalNumberOfTasks((int) runtimeContext.getCounter(DAGCounter.class.getName(),
        DAGCounter.TOTAL_LAUNCHED_TASKS.name()));
    record.setNumberOfSucceededTasks((int) runtimeContext.getCounter(DAGCounter.class.getName(),
        DAGCounter.NUM_SUCCEEDED_TASKS.name()));
    record.setNumberOfKilledTasks((int) runtimeContext.getCounter(DAGCounter.class.getName(),
        DAGCounter.NUM_KILLED_TASKS.name()));
    record.setNumberOfFailedTasks((int) runtimeContext.getCounter(DAGCounter.class.getName(),
        DAGCounter.NUM_FAILED_TASKS.name()));
    record.setTaskDurationMillis(runtimeContext.getCounter(DAGCounter.class.getName(),
        DAGCounter.WALL_CLOCK_MILLIS.name()));
    record.setNodeUsedCount((int) runtimeContext.getCounter(DAGCounter.class.getName(),
        DAGCounter.NODE_USED_COUNT.name()));
    record.setNodeTotalCount((int) runtimeContext.getCounter(DAGCounter.class.getName(),
        DAGCounter.NODE_TOTAL_COUNT.name()));
    record.setReduceInputGroups(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.REDUCE_INPUT_GROUPS.name()));
    record.setReduceInputRecords(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.REDUCE_INPUT_RECORDS.name()));
    record.setSpilledRecords(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.SPILLED_RECORDS.name()));
    record.setNumShuffledInputs(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.NUM_SHUFFLED_INPUTS.name()));
    record.setNumFailedShuffleInputs(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.NUM_FAILED_SHUFFLE_INPUTS.name()));
    record.setInputRecordsProcessed(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.INPUT_RECORDS_PROCESSED.name()));
    record.setInputSplitLengthBytes(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.INPUT_SPLIT_LENGTH_BYTES.name()));
    record.setOutputRecords(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.OUTPUT_RECORDS.name()));
    record.setOutputBytesPhysical(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.OUTPUT_BYTES_PHYSICAL.name()));
    record.setShuffleChunkCount(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.SHUFFLE_CHUNK_COUNT.name()));
    record.setShuffleBytes(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.SHUFFLE_BYTES.name()));
    record.setShuffleBytesDiskDirect(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.SHUFFLE_BYTES_DISK_DIRECT.name()));
    record.setShufflePhaseTime(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.SHUFFLE_PHASE_TIME.name()));
    record.setMergePhaseTime(runtimeContext.getCounter(TaskCounter.class.getName(),
        TaskCounter.MERGE_PHASE_TIME.name()));
  }
With query history, a more detailed HiveOperation-based query classification is introduced without breaking the
original one. If there is an SqlKind stored in the QueryState, the record will contain it.
ql/src/java/org/apache/hadoop/hive/ql/queryhistory/RecordEnricher.java