Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-18268

Hive Prepared Statement when split with double quoted in query fails

    Details

    • Type: Bug
    • Status: Patch Available
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3.2
    • Fix Version/s: None
    • Component/s: JDBC
    • Labels:
      None

      Description

      HIVE-13625, Change sql statement split when odd number of escape characters, and add parameter counter validation, above

      // prev code
          StringBuilder newSql = new StringBuilder(parts.get(0));
          for(int i=1;i<parts.size();i++){
            if(!parameters.containsKey(i)){
              throw new SQLException("Parameter #"+i+" is unset");
            }
            newSql.append(parameters.get(i));
            newSql.append(parts.get(i));
          }
      
      // change from HIVE-13625
          int paramLoc = 1;
          while (getCharIndexFromSqlByParamLocation(sql, '?', paramLoc) > 0) {
            // check the user has set the needs parameters
            if (parameters.containsKey(paramLoc)) {
              int tt = getCharIndexFromSqlByParamLocation(newSql.toString(), '?', 1);
              newSql.deleteCharAt(tt);
              newSql.insert(tt, parameters.get(paramLoc));
            }
            paramLoc++;
          }
      

      If the number of split SQL and the number of parameters are not matched, an SQLException is thrown

      Currently, when splitting SQL, there is no processing for double quoted, and when the token ('?' ) is between double quote, SQL is split.

      i think when the token between double quoted is literal, it is correct to not split.

      for example, above the query;

      // Some comments here
      1:  String query =  " select 1 from x where qa="?" "
      2:  String query = " SELECT 1 FROM `x` WHERE (trecord LIKE "ALA[d_?]%")
      

      ? is literal, then query do not split.

        Attachments

        1. HIVE-18268.1.patch
          3 kB
          Choi JaeHwan
        2. HIVE-18268.2.patch
          3 kB
          Choi JaeHwan
        3. HIVE-18268.3.patch
          3 kB
          Choi JaeHwan
        4. HIVE-18268.4.patch
          3 kB
          Choi JaeHwan
        5. HIVE-18268.patch
          3 kB
          Choi JaeHwan

          Issue Links

            Activity

              People

              • Assignee:
                prismsoft Choi JaeHwan
                Reporter:
                prismsoft Choi JaeHwan
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: