private void checkValues(SessionState ss, QueryState queryState, DriverContext driverContext,
      Record record) throws Exception {
    // guard counter to make the test fail if a new field is added to the schema which wasn't covered here
    // in case of field addition, it can be decided whether the new field is suitable for testing or not and adapt
    // accordingly
    TezRuntimeContext runtimeContext = driverContext.getRuntimeContext();
    final int ALL_FIELDS =  Schema.Field.values().length;

    Set<Schema.Field> notTestedFields = Sets.newHashSet(
        Schema.Field.QUERY_HISTORY_SCHEMA_VERSION,
        Schema.Field.HIVE_VERSION);
    final int FIELDS_TO_BE_VALIDATED = ALL_FIELDS - notTestedFields.size();
    LOG.info("Comparing input driverContext ({}) to the record to be flushed ({})", driverContext, record);

    AtomicInteger fieldsValidated = new AtomicInteger(0);

    compareValue(Schema.Field.QUERY_ID, queryState.getQueryId(), record, fieldsValidated);
    compareValue(Schema.Field.SESSION_ID, ss.getSessionId(), record, fieldsValidated);
    compareValue(Schema.Field.OPERATION_ID, DummyRecord.OPERATION_ID, record, fieldsValidated);
    compareValue(Schema.Field.EXECUTION_ENGINE, DummyRecord.EXECUTION_ENGINE, record,
        fieldsValidated);
    compareValue(Schema.Field.EXECUTION_MODE, DummyRecord.EXECUTION_MODE, record,
        fieldsValidated);
    compareValue(Schema.Field.TEZ_DAG_ID, DummyRecord.DAG_ID, record, fieldsValidated);
    compareValue(Schema.Field.TEZ_APP_ID, DummyRecord.TEZ_APPLICATION_ID, record,
        fieldsValidated);
    compareValue(Schema.Field.TEZ_SESSION_ID, DummyRecord.TEZ_SESSION_ID, record,
        fieldsValidated);
    compareValue(Schema.Field.CLUSTER_ID, ServiceContext.findClusterId(), record, fieldsValidated);
    compareValue(Schema.Field.SQL, DummyRecord.SQL, record, fieldsValidated);
    compareValue(Schema.Field.SESSION_TYPE, DummyRecord.SESSION_TYPE, record,
        fieldsValidated);
    compareValue(Schema.Field.HIVERSERVER2_PROTOCOL_VERSION,
        DummyRecord.HIVERSERVER2_PROTOCOL_VERSION, record, fieldsValidated);

    boolean doAsEnabled = ss.getConf().getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS);
    compareValue(Schema.Field.CLUSTER_USER,
        doAsEnabled ? ss.getUserName() : Utils.getUGI().getShortUserName(), record, fieldsValidated);

    // doAs=false, END_USER is the current user (usually "hive" on a cluster)
    compareValue(Schema.Field.END_USER, ss.getUserName(), record, fieldsValidated);
    compareValue(Schema.Field.DB_NAME, DummyRecord.CURRENT_DATABASE, record, fieldsValidated);
    compareValue(Schema.Field.TEZ_COORDINATOR, DummyRecord.TEZ_AM_ADDRESS, record, fieldsValidated);
    compareValue(Schema.Field.QUERY_STATE, DummyRecord.QUERY_STATE, record, fieldsValidated);
    compareValue(Schema.Field.QUERY_TYPE, DummyRecord.QUERY_TYPE.getName(), record,
        fieldsValidated);
    compareValue(Schema.Field.OPERATION, DummyRecord.OPERATION, record, fieldsValidated);
    compareValue(Schema.Field.SERVER_ADDRESS, serviceContext.getHost(), record, fieldsValidated);
    compareValue(Schema.Field.SERVER_PORT, serviceContext.getPort(), record, fieldsValidated);
    compareValue(Schema.Field.CLIENT_ADDRESS, DummyRecord.CLIENT_ADDRESS, record, fieldsValidated);

    compareValue(Schema.Field.START_TIME_UTC,
        Timestamp.ofEpochMilli(driverContext.getQueryInfo().getBeginTime()), record,
        fieldsValidated);
    compareValue(Schema.Field.START_TIME,
        Timestamp.ofEpochMilli(driverContext.getQueryInfo().getBeginTime(), ZoneId.systemDefault()),
        record,
        fieldsValidated);
    compareValue(Schema.Field.END_TIME_UTC,
        Timestamp.ofEpochMilli(driverContext.getQueryInfo().getEndTime()), record,
        fieldsValidated);
    compareValue(Schema.Field.END_TIME,
        Timestamp.ofEpochMilli(driverContext.getQueryInfo().getEndTime(), ZoneId.systemDefault()),
        record,
        fieldsValidated);

    compareValue(Schema.Field.TOTAL_TIME_MS, DummyRecord.TOTAL_TIME, record, fieldsValidated);

    // perfLogger values
    compareValue(Schema.Field.PLANNING_DURATION,
        SessionState.getPerfLogger().getEndTime(PerfLogger.COMPILE) - SessionState.getPerfLogger()
            .getStartTime(PerfLogger.COMPILE),
        record,
        fieldsValidated);
    compareValue(Schema.Field.PLANNING_START_TIME,
        Timestamp.ofEpochMilli(SessionState.getPerfLogger().getStartTime(PerfLogger.COMPILE), ZoneId.systemDefault()),
        record,
        fieldsValidated);
    compareValue(Schema.Field.PREPARE_PLAN_DURATION,
        SessionState.getPerfLogger().getPreparePlanDuration(),
        record,
        fieldsValidated);
    compareValue(Schema.Field.PREPARE_PLAN_START_TIME,
        Timestamp.ofEpochMilli(SessionState.getPerfLogger().getEndTime(PerfLogger.COMPILE), ZoneId.systemDefault()),
        record,
        fieldsValidated);
    compareValue(Schema.Field.GET_SESSION_DURATION,
        SessionState.getPerfLogger().getEndTime(PerfLogger.TEZ_GET_SESSION) - SessionState.getPerfLogger()
            .getStartTime(PerfLogger.TEZ_GET_SESSION), record,
        fieldsValidated);
    compareValue(Schema.Field.GET_SESSION_START_TIME,
        Timestamp.ofEpochMilli(SessionState.getPerfLogger().getStartTime(PerfLogger.TEZ_GET_SESSION),
            ZoneId.systemDefault()), record,
        fieldsValidated);
    compareValue(Schema.Field.EXECUTION_DURATION,
        SessionState.getPerfLogger().getEndTime(PerfLogger.TEZ_RUN_DAG) - SessionState.getPerfLogger()
            .getStartTime(PerfLogger.TEZ_RUN_DAG), record,
        fieldsValidated);
    compareValue(Schema.Field.EXECUTION_START_TIME,
        Timestamp.ofEpochMilli(SessionState.getPerfLogger().getStartTime(PerfLogger.TEZ_RUN_DAG),
            ZoneId.systemDefault()), record,
        fieldsValidated);

    compareValue(Schema.Field.FAILURE_REASON, DummyRecord.FAILURE_REASON, record,
        fieldsValidated);
    compareValue(Schema.Field.NUM_ROWS_FETCHED, DummyRecord.NUM_ROWS_FETCHED, record,
        fieldsValidated);
    compareValue(Schema.Field.PLAN, DummyRecord.PLAN, record, fieldsValidated);
    compareValue(Schema.Field.USED_TABLES, String.join(",",
        DummyRecord.USED_TABLES), record, fieldsValidated);
    compareValue(Schema.Field.EXEC_SUMMARY, DummyRecord.EXEC_SUMMARY, record,
        fieldsValidated);
    compareValue(Schema.Field.CONFIGURATION_OPTIONS_CHANGED,
        Joiner.on(";").withKeyValueSeparator("=").join(DummyRecord.CONFIGURATION_OPTIONS_CHANGED),
        record, fieldsValidated);
    compareValue(Schema.Field.TOTAL_LAUNCHED_TASKS,
        DummyRecord.TOTAL_LAUNCHED_TASKS, record, fieldsValidated);
    compareValue(Schema.Field.NUM_SUCCEEDED_TASKS,
        DummyRecord.NUM_SUCCEEDED_TASKS, record, fieldsValidated);
    compareValue(Schema.Field.NUM_KILLED_TASKS,
        DummyRecord.NUM_KILLED_TASKS, record, fieldsValidated);
    compareValue(Schema.Field.NUM_FAILED_TASKS,
        DummyRecord.NUM_FAILED_TASKS, record, fieldsValidated);
    compareValue(Schema.Field.TASK_DURATION_MILLIS,
        DummyRecord.TASK_DURATION_MILLIS, record, fieldsValidated);
    compareValue(Schema.Field.NODE_USED_COUNT,
        DummyRecord.NODE_USED_COUNT, record, fieldsValidated);
    compareValue(Schema.Field.NODE_TOTAL_COUNT,
        DummyRecord.NODE_TOTAL_COUNT, record, fieldsValidated);
    compareValue(Schema.Field.REDUCE_INPUT_GROUPS,
        DummyRecord.REDUCE_INPUT_GROUPS, record, fieldsValidated);
    compareValue(Schema.Field.REDUCE_INPUT_RECORDS,
        DummyRecord.REDUCE_INPUT_RECORDS, record, fieldsValidated);
    compareValue(Schema.Field.SPILLED_RECORDS,
        DummyRecord.SPILLED_RECORDS, record, fieldsValidated);
    compareValue(Schema.Field.NUM_SHUFFLED_INPUTS,
        DummyRecord.NUM_SHUFFLED_INPUTS, record, fieldsValidated);
    compareValue(Schema.Field.NUM_FAILED_SHUFFLE_INPUTS,
        DummyRecord.NUM_FAILED_SHUFFLE_INPUTS, record, fieldsValidated);
    compareValue(Schema.Field.INPUT_RECORDS_PROCESSED,
        DummyRecord.INPUT_RECORDS_PROCESSED, record, fieldsValidated);
    compareValue(Schema.Field.INPUT_SPLIT_LENGTH_BYTES,
        DummyRecord.INPUT_SPLIT_LENGTH_BYTES, record, fieldsValidated);
    compareValue(Schema.Field.OUTPUT_RECORDS,
        DummyRecord.OUTPUT_RECORDS, record, fieldsValidated);
    compareValue(Schema.Field.OUTPUT_BYTES_PHYSICAL,
        DummyRecord.OUTPUT_BYTES_PHYSICAL, record, fieldsValidated);
    compareValue(Schema.Field.SHUFFLE_CHUNK_COUNT,
        DummyRecord.SHUFFLE_CHUNK_COUNT, record, fieldsValidated);
    compareValue(Schema.Field.SHUFFLE_BYTES,
        DummyRecord.SHUFFLE_BYTES, record, fieldsValidated);
    compareValue(Schema.Field.SHUFFLE_BYTES_DISK_DIRECT,
        DummyRecord.SHUFFLE_BYTES_DISK_DIRECT, record, fieldsValidated);
    compareValue(Schema.Field.SHUFFLE_PHASE_TIME,
        DummyRecord.SHUFFLE_PHASE_TIME, record, fieldsValidated);
    compareValue(Schema.Field.MERGE_PHASE_TIME,
        DummyRecord.MERGE_PHASE_TIME, record, fieldsValidated);

    if (fieldsValidated.get() != FIELDS_TO_BE_VALIDATED) {
      Assert.fail(
          "Less (or more?) fields have been validated than expected: all: " + ALL_FIELDS + ", expected: "
              + FIELDS_TO_BE_VALIDATED + ", actual: " + fieldsValidated.get());
    }
  }
This unit test asserts that the record is created as expected from the various hive source objects like:
DriverContext, SessionState, QueryInfo, etc.
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/queryhistory/TestQueryHistoryService.java