private List<String> splitSqlStatement(String sql) {
    List<String> parts = new ArrayList<>();
    int apCount = 0;
    int off = 0;
    boolean skip = false;

    for (int i = 0; i < sql.length(); i++) {
      char c = sql.charAt(i);
      if (skip) {
        skip = false;
        continue;
      }
      switch (c) {
      case '\'':
        apCount++;
        break;
      case '\\':
        skip = true;
        break;
      case '?':
        if ((apCount & 1) == 0) {
          parts.add(sql.substring(off,i));
          off=i+1;
        }
        break;
      default:
        break;
      }
    }
    parts.add(sql.substring(off, sql.length()));
    return parts;
  }
Splits the parametered sql statement at parameter boundaries.

taking into account ' and \ escaping.

output for: 'select 1 from ? where a = ?'
 ['select 1 from ',' where a = ','']

@param sql
@return
jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java