private void setupSessionIO(SessionState sessionState) {
    try {
      log.info("Putting temp output to file " + sessionState.getTmpOutputFile()
          + " and error output to file " + sessionState.getTmpErrOutputFile());
      sessionState.in = null; // hive server's session input stream is not used
      // open a per-session file in auto-flush mode for writing temp results and tmp error output
      sessionState.out = new SessionStream(
          new FileOutputStream(sessionState.getTmpOutputFile()), true,
          StandardCharsets.UTF_8.name());
      sessionState.err = new SessionStream(
          new FileOutputStream(sessionState.getTmpErrOutputFile()), true,
          StandardCharsets.UTF_8.name());
    } catch (IOException e) {
      log.error("Error in creating temp output file", e);

      // Close file streams to avoid resource leaking
      ServiceUtils.cleanup(log, parentSession.getSessionState().out, parentSession.getSessionState().err);

      try {
        sessionState.in = null;
        sessionState.out =
            new SessionStream(System.out, true, StandardCharsets.UTF_8.name());
        sessionState.err =
            new SessionStream(System.err, true, StandardCharsets.UTF_8.name());
      } catch (UnsupportedEncodingException ee) {
        log.error("Error creating PrintStream", e);
        sessionState.out = null;
        sessionState.err = null;
      }
    }
  }
For processors other than Hive queries (Driver), they output to session.out (a temp file)
first and the fetchOne/fetchN/fetchAll functions get the output from pipeIn.
service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java