private static void start(SessionState startSs, boolean isAsync, LogHelper console) {
    // Starting from ORC 2.x, ZSTD is the default compression codec and is implemented using the zstd-jni library.
    // To fallback to the pure Java implementation (Aircompressor), set the appropriate configuration property.
    // TODO: ZSTD with zstd-jni is currently not yet supported in Hive.
    System.setProperty("orc.compression.zstd.impl", "java");
    setCurrentSessionState(startSs);

    if (!startSs.isStarted.compareAndSet(false, true)) {
      return;
    }

    if (startSs.hiveHist == null){
      if (startSs.getConf().getBoolVar(HiveConf.ConfVars.HIVE_SESSION_HISTORY_ENABLED)) {
        startSs.hiveHist = new HiveHistoryImpl(startSs);
      } else {
        // Hive history is disabled, create a no-op proxy
        startSs.hiveHist = HiveHistoryProxyHandler.getNoOpHiveHistoryProxy();
      }
    }

    // Get the following out of the way when you start the session these take a
    // while and should be done when we start up.
    try {
      UserGroupInformation sessionUGI = Utils.getUGI();
      FileSystem.get(startSs.sessionConf);

      // Create scratch dirs for this session
      startSs.createSessionDirs(sessionUGI.getShortUserName());

      // Set temp file containing results to be sent to HiveClient
      if (startSs.getTmpOutputFile() == null) {
        try {
          startSs.setTmpOutputFile(createTempFile(startSs.getConf()));
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      // Set temp file containing error output to be sent to client
      if (startSs.getTmpErrOutputFile() == null) {
        try {
          startSs.setTmpErrOutputFile(createTempFile(startSs.getConf()));
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      // Catch-all due to some exec time dependencies on session state
      // that would cause ClassNoFoundException otherwise
      throw new RuntimeException(e);
    }

    String engine = HiveConf.getVar(startSs.getConf(), HiveConf.ConfVars.HIVE_EXECUTION_ENGINE);

    if (!engine.equals("tez") || startSs.isHiveServerQuery
            || !HiveConf.getBoolVar(startSs.getConf(), ConfVars.HIVE_CLI_TEZ_INITIALIZE_SESSION)) {
      return;
    }

    try {
      if (startSs.tezSessionState == null) {
        startSs.setTezSession(new TezSessionState(startSs.getSessionId(), startSs.sessionConf));
      } else {
        // Only TezTask sets this, and then removes when done, so we don't expect to see it.
        LOG.warn("Tez session was already present in SessionState before start: "
            + startSs.tezSessionState);
      }
      if (startSs.tezSessionState.isOpen()) {
        return;
      }
      if (startSs.tezSessionState.isOpening()) {
        if (!isAsync) {
          startSs.tezSessionState.endOpen();
        }
        return;
      }
      // Neither open nor opening.
      if (!isAsync) {
        startSs.tezSessionState.open();
      } else {
        startSs.tezSessionState.beginOpen(null, console);
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
set current session to existing session object if a thread is running
multiple sessions - it must call this method with the new session object
when switching from one session to another.
ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java