@Override
  protected void onNewState(final OperationState state, final OperationState prevState) {
    super.onNewState(state, prevState);

    currentSQLStateScope = updateOperationStateMetrics(currentSQLStateScope,
        MetricsConstant.SQL_OPERATION_PREFIX,
        MetricsConstant.COMPLETED_SQL_OPERATION_PREFIX, state);

    final Optional<Metrics> metrics = Optional.ofNullable(MetricsFactory.getInstance());
    if (metrics.isPresent()) {
      // New state is changed to running from something else (user is active)
      if (state == OperationState.RUNNING && prevState != state) {
        incrementUserQueries(metrics.get());
      }
      // New state is not running (user not active) any more
      if (prevState == OperationState.RUNNING && prevState != state) {
        decrementUserQueries(metrics.get());
      }
    }

    switch (state) {
    case CANCELED:
      queryInfo.setRuntime(getOperationComplete() - getOperationStart());
      if (metrics.isPresent() && submittedQryScp.isPresent()) {
        metrics.get().endScope(submittedQryScp.get());
      }
      queryInfo.updateState(state.toString());
      break;
    case CLOSED:
      queryInfo.setEndTime();
      break;
    case ERROR:
      queryInfo.setRuntime(getOperationComplete() - getOperationStart());
      if (metrics.isPresent() && submittedQryScp.isPresent()) {
        metrics.get().endScope(submittedQryScp.get());
      }
      markQueryMetric(MetricsFactory.getInstance(), MetricsConstant.HS2_FAILED_QUERIES);
      queryInfo.updateState(state.toString());
      break;
    case FINISHED:
      queryInfo.setRuntime(getOperationComplete() - getOperationStart());
      if (metrics.isPresent() && submittedQryScp.isPresent()) {
        metrics.get().endScope(submittedQryScp.get());
      }
      markQueryMetric(MetricsFactory.getInstance(), MetricsConstant.HS2_SUCCEEDED_QUERIES);
      queryInfo.updateState(state.toString());
      break;
    case INITIALIZED:
      /* fall through */
    case PENDING:
      /* fall through */
    case RUNNING:
      /* fall through */
    case TIMEDOUT:
      /* fall through */
    case UNKNOWN:
      /* fall through */
    default:
      queryInfo.updateState(state.toString());
      break;
    }
  }
Get summary information of this SQLOperation for display in WebUI.
service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java