CommandProcessorResponse processLocalCmd(String cmd, CommandProcessor proc, CliSessionState ss)
      throws CommandProcessorException {
    boolean escapeCRLF = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_CLI_PRINT_ESCAPE_CRLF);
    CommandProcessorResponse response = new CommandProcessorResponse();

    if (proc != null) {
      if (proc instanceof IDriver) {
        IDriver qp = (IDriver) proc;
        PrintStream out = ss.out;
        long start = System.currentTimeMillis();
        if (ss.getIsVerbose()) {
          out.println(cmd);
        }

        // Set HDFS CallerContext to queryId and reset back to sessionId after the query is done
        ShimLoader.getHadoopShims()
            .setHadoopQueryContext(String.format(USER_ID, qp.getQueryState().getQueryId(), ss.getUserName()));
        try {
          response = qp.run(cmd);
        } catch (CommandProcessorException e) {
          qp.close();
          ShimLoader.getHadoopShims()
              .setHadoopSessionContext(String.format(USER_ID, ss.getSessionId(), ss.getUserName()));
          throw e;
        }

        // query has run capture the time
        long end = System.currentTimeMillis();
        double timeTaken = (end - start) / 1000.0;

        ArrayList<String> res = new ArrayList<String>();

        printHeader(qp, out);

        // print the results
        int counter = 0;
        try {
          if (out instanceof FetchConverter) {
            ((FetchConverter) out).fetchStarted();
          }
          while (qp.getResults(res)) {
            for (String r : res) {
                  if (escapeCRLF) {
                    r = EscapeCRLFHelper.escapeCRLF(r);
                  }
              out.println(r);
            }
            counter += res.size();
            res.clear();
            if (out.checkError()) {
              break;
            }
          }
        } catch (IOException e) {
          console.printError("Failed with exception " + e.getClass().getName() + ":" + e.getMessage(),
              "\n" + org.apache.hadoop.util.StringUtils.stringifyException(e));
          throw new CommandProcessorException(1);
        } finally {
          qp.close();
          ShimLoader.getHadoopShims()
              .setHadoopSessionContext(String.format(USER_ID, ss.getSessionId(), ss.getUserName()));

          if (out instanceof FetchConverter) {
            ((FetchConverter) out).fetchFinished();
          }

          console.printInfo(
              "Time taken: " + timeTaken + " seconds" + (counter == 0 ? "" : ", Fetched: " + counter + " row(s)"));
        }
      } else {
        String firstToken = tokenizeCmd(cmd.trim())[0];
        String cmd_1 = getFirstCmd(cmd.trim(), firstToken.length());

        if (ss.getIsVerbose()) {
          ss.out.println(firstToken + " " + cmd_1);
        }

        try {
          CommandProcessorResponse res = proc.run(cmd_1);
          if (res.getMessage() != null) {
            console.printInfo(res.getMessage());
          }
          return res;
        } catch (CommandProcessorException e) {
          ss.out.println("Query returned non-zero code: " + e.getResponseCode() + ", cause: " + e.getMessage());
          throw e;
        }
      }
    }
    return response;
  }
Extract and clean up the first command in the input.
cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java