private <T> T callWithRetryAndReconnect(TFunction<T> rpc, Function<T, TSStatus> statusGetter)
      throws SQLException, TException {
    TException lastTException = null;
    T result = null;
    int retryAttempt;
    int maxRetryCount = 5;
    int retryIntervalInMs = 1000;
    for (retryAttempt = 0; retryAttempt <= maxRetryCount; retryAttempt++) {
      // 1. try to execute the rpc
      try {
        result = rpc.run();
        lastTException = null;
      } catch (TException e) {
        result = null;
        lastTException = e;
      }

      TSStatus status = null;
      if (result != null) {
        status = statusGetter.apply(result);
      }
      // success, return immediately
      if (status != null && !(status.isSetNeedRetry() && status.isNeedRetry())) {
        return result;
      }

      // prepare for the next retry
      if (lastTException != null) {
        reConnect();
      }
      try {
        TimeUnit.MILLISECONDS.sleep(retryIntervalInMs);
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        break;
      }
    }

    if (result == null && lastTException != null) {
      throw lastTException;
    }
    return result;
  }
Execute a SQL encoded in bytes with {@link IoTDBStatement#charset}.

@param sql raw sql in bytes encoded with {@link IoTDBStatement#charset}
@return true if the first result is a {@link ResultSet} object; false if the first result is an
    update count or there is no result
@throws SQLException if a database access error occurs
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java