private String replaceBackSlashSingleQuote(String x) {
    // scrutinize escape pair, specifically, replace \' to '
    StringBuffer newX = new StringBuffer();
    for (int i = 0; i < x.length(); i++) {
      char c = x.charAt(i);
      if (c == '\\' && i < x.length() - 1) {
        char c1 = x.charAt(i + 1);
        if (c1 == '\'') {
          newX.append(c1);
        } else {
          newX.append(c);
          newX.append(c1);
        }
        i++;
      } else {
        newX.append(c);
      }
    }
    return newX.toString();
  }
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