Uploaded image for project: 'Kylin'
  1. Kylin
  2. KYLIN-4069

HivePushDownConverter.doConvert will change sql semantics in some scenarios

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: v2.6.2
    • Fix Version/s: None
    • Component/s: Query Engine
    • Labels:
      None

      Description

      HivePushDownConverter.doConvert source code is as follows:

      public static String doConvert(String originStr, boolean isPrepare) {
              // Step1.Replace " with `
              String convertedSql = replaceString(originStr, "\"", "`");
      
              // Step2.Replace extract functions
              convertedSql = extractReplace(convertedSql);
      
              // Step3.Replace cast type string
              convertedSql = castReplace(convertedSql);
      
              // Step4.Replace sub query
              convertedSql = subqueryReplace(convertedSql);
      
              // Step5.Replace char_length with length
              convertedSql = replaceString(convertedSql, "CHAR_LENGTH", "LENGTH");
              convertedSql = replaceString(convertedSql, "char_length", "length");
      
              // Step6.Replace "||" with concat
              convertedSql = concatReplace(convertedSql);
      
              // Step7.Add quote for interval in timestampadd
              convertedSql = timestampAddDiffReplace(convertedSql);
      
              // Step8.Replace integer with int
              convertedSql = replaceString(convertedSql, "INTEGER", "INT");
              convertedSql = replaceString(convertedSql, "integer", "int");
      
              // Step9.Add limit 1 for prepare select sql to speed up
              if (isPrepare) {
                  convertedSql = addLimit(convertedSql);
              }
      
              return convertedSql;
          }
      

      It is not advisable to directly replace the sql text. The following example will convert sql to another error sql:

      SELECT "CHAR_LENGTH" FROM datasource.a
      

      will convert to

      SELECT `LENGTH` FROM datasource.a
      

      Every use of replaceString in doConvert will cause such problems.

        Attachments

          Activity

            People

            • Assignee:
              codingforfun weibin0516
              Reporter:
              codingforfun weibin0516
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: