@Override
  public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
    List<InputSplit> ins = new ArrayList<InputSplit>();

    if (url == null) url = job.get(URL_KEY);
    if (query == null) query = job.get(QUERY_KEY);
    if (user == null) user = job.get(USER_KEY);
    if (pwd == null) pwd = job.get(PWD_KEY);
    String database = job.get(DB_KEY);

    if (url == null || query == null) {
      throw new IllegalStateException();
    }

    String handleId = job.get(HANDLE_ID);
    if (handleId == null) {
      handleId = UUID.randomUUID().toString();
      LOG.info("Handle ID not specified - generated handle ID {}", handleId);
    }

    try {
      Class.forName(driverName);
    } catch (ClassNotFoundException e) {
      throw new IOException(e);
    }

    LOG.info("Handle ID {}: query={}", handleId, query);
    String escapedQuery = StringUtils.escapeString(query, ESCAPE_CHAR, escapedChars);
    String sql = String.format(SPLIT_QUERY, escapedQuery, numSplits);
    try {
      Connection conn = DriverManager.getConnection(url,user,pwd);
      try (
        Statement stmt = conn.createStatement();
      ) {
        if (database != null && !database.isEmpty()) {
          stmt.execute("USE " + database);
        }
        String sessionQueries = job.get(SESSION_QUERIES_FOR_GET_NUM_SPLITS);
        if (sessionQueries != null && !sessionQueries.trim().isEmpty()) {
          String[] queries = sessionQueries.trim().split(",");
          for (String q : queries) {
            //allow only set queries
            if (SET_QUERY_PATTERN.matcher(q).matches()) {
              LOG.debug("Executing session query: {}", q);
              stmt.execute(q);
            } else {
              LOG.warn("Only SET queries are allowed, not executing this query: {}", q);
            }
          }
        }

        // In case of USE_NEW_SPLIT_FORMAT=true, following format is used
        //       type                  split
        // schema-split             LlapInputSplit -- contains only schema
        // plan-split               LlapInputSplit -- contains only planBytes[]
        // 0                        LlapInputSplit -- actual split 1
        // 1                        LlapInputSplit -- actual split 2
        // ...                         ...
        boolean useNewSplitFormat = job.getBoolean(USE_NEW_SPLIT_FORMAT, false);

        ResultSet res = stmt.executeQuery(sql);
        int count = 0;
        LlapInputSplit schemaSplit = null;
        LlapInputSplit planSplit = null;
        while (res.next()) {
          // deserialize split
          DataInput in = new DataInputStream(res.getBinaryStream(2));
          LlapInputSplit is = new LlapInputSplit();
          is.readFields(in);
          if (useNewSplitFormat) {
            ins.add(is);
          } else {
            // to keep the old format, populate schema and planBytes[] in actual splits
            if (count == 0) {
              schemaSplit = is;
              if (numSplits == 0) {
                ins.add(schemaSplit);
              }
            } else if (count == 1) {
              planSplit = is;
            } else {
              is.setSchema(schemaSplit.getSchema());
              assert planSplit != null;
              is.setPlanBytes(planSplit.getPlanBytes());
              ins.add(is);
            }
            count++;
          }
        }
        res.close();
      } catch (Exception e) {
        LOG.error("Closing connection due to error", e);
        conn.close();
        throw e;
      }

      // Keep connection open to hang on to associated resources (temp tables, locks).
      // Save to connectionMap so it can be closed at user's convenience.
      addConnection(handleId, conn);
    } catch (Exception e) {
      throw new IOException(e);
    }
    return ins.toArray(new InputSplit[ins.size()]);
  }
Calling getSplits() will open a HiveServer2 connection which should be closed by the calling application
using LlapBaseInputFormat.close() when the application is done with the splits.
llap-ext-client/src/java/org/apache/hadoop/hive/llap/LlapBaseInputFormat.java