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

LIKE Operator with % does not match when column contains newline

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.12.0
    • Component/s: core
    • Labels:
      None

      Description

      If I have a column where some rows contain a newline, then using a % does not match as it should. For example, if I have a column named 'foo' where a row contains 'My\nValue' then the following query I would expect to match:

      SELECT * FROM MyTable WHERE foo LIKE 'M%'

      However, this row is not returned by the above query. This appears to be a bug in the regex generated by the org.apache.calcite.runtime.Like class, as it generates '.*' for the %, but in Java the dot character does not match newlines unless it is compiled in dot-all mode.

        Issue Links

          Activity

          Hide
          markap14 Mark Payne added a comment -

          I created a PR that works for my use case. I'm not sure how to really create a unit test for this, but I've verified it manually. Let me know if I'm off base here, and this is not how this should work.

          Thanks!
          -Mark

          Show
          markap14 Mark Payne added a comment - I created a PR that works for my use case. I'm not sure how to really create a unit test for this, but I've verified it manually. Let me know if I'm off base here, and this is not how this should work. Thanks! -Mark
          Hide
          julianhyde Julian Hyde added a comment -

          Can you add one or two tests to SqlOperatorBaseTest.testLikeOperator?

          Show
          julianhyde Julian Hyde added a comment - Can you add one or two tests to SqlOperatorBaseTest.testLikeOperator ?
          Hide
          markap14 Mark Payne added a comment -

          Julian Hyde - thanks for pointing me in the right direction for unit tests. Makes a lot of sense to add them there. I added two unit tests. Verified that they failed without the patch and pass with the patch. Updated the PR accordingly. Thanks!

          Show
          markap14 Mark Payne added a comment - Julian Hyde - thanks for pointing me in the right direction for unit tests. Makes a lot of sense to add them there. I added two unit tests. Verified that they failed without the patch and pass with the patch. Updated the PR accordingly. Thanks!
          Hide
          julianhyde Julian Hyde added a comment -
          Show
          julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/58217cb2 . Thanks for the PR, Mark Payne !
          Hide
          markap14 Mark Payne added a comment -

          Awesome, thanks for the quick turnaround!

          Show
          markap14 Mark Payne added a comment - Awesome, thanks for the quick turnaround!
          Hide
          julianhyde Julian Hyde added a comment -

          Resolved in release 1.12.0 (2017-03-24).

          Show
          julianhyde Julian Hyde added a comment - Resolved in release 1.12.0 (2017-03-24).

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              markap14 Mark Payne
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development