Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6433

SUBSTRING can return incorrect empty result for some parameters

    XMLWordPrintableJSON

Details

    Description

      SUBSTRING function for cases when 3rd parameter (length) more than
      Integer.MAX_VALUE can return empty result due to code do clamp
       that value and after that it can't be more than Integer.MAX_VALUE.
      Simple way to reproduce :
      append into SqlOperatorTest smth like:

          f.checkScalar(
              String.format("{fn SUBSTRING('abcdef', %d, %d)}", Integer.MIN_VALUE, 10L + Integer.MAX_VALUE),
              "abcdef",
              "VARCHAR(6) NOT NULL");
      
      

      it`s all due to check after clamping

      public static String substring(String c, int s, int l) {
        ....
        long e = (long) s + (long) l; -- here we can got incorrect length 
        .....
        if (s > lc || e < 1L) {
          return "";
        }
      .....

       

       

      Attachments

        Issue Links

          Activity

            People

              zstan Evgeny Stanilovsky
              jooger Iurii Gerzhedovich
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: