Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchors not working as expected with case-insensitive regex #7906

Closed
sethm opened this issue Jan 30, 2017 · 2 comments
Closed

Anchors not working as expected with case-insensitive regex #7906

sethm opened this issue Jan 30, 2017 · 2 comments
Assignees
Labels
area/influxql Issues related to InfluxQL query language kind/bug
Milestone

Comments

@sethm
Copy link

sethm commented Jan 30, 2017

Bug report

System info: InfluxDB 1.2.0 on OS X 10.12.2 (installed with Homebrew)

Steps to reproduce:

  1. Create a test database

  2. Populate with test data

     h2o_feet,location=santa_monica water_level=10 0
     h2o_feet,location=santa_monica water_level=12 10000000000
     h2o_feet,location=santa_monica water_level=11 20000000000
     h2o_feet,location=santa_monica water_level=13 30000000000
    
  3. Attempt to use a case-insensitive regular expression with anchors:

     SELECT * FROM h2o_feet WHERE location =~ /(?i)^SANTA_MONICA$/
    

Expected behavior: Should return four rows

Actual behavior: Returns no rows

Additional info: Note that leaving off EITHER anchor returns the expected rows. Replacing either anchor with \b also returns expected rows.

@e-dard e-dard added kind/bug area/influxql Issues related to InfluxQL query language labels Jan 31, 2017
@e-dard e-dard self-assigned this Jan 31, 2017
@e-dard
Copy link
Contributor

e-dard commented Jan 31, 2017

@sethm thanks for this report. I think I know where the issue is. As a workaround for the moment you could, as you suggest, use =~ /(?i)^SANTA_MONICA/ or =~ /(?i)SANTA_MONICA$/ or =~ /(?i)SANTA_MONICA/ if any of those are precise enough for you.

@sethm
Copy link
Author

sethm commented Jan 31, 2017

Addendum: I just discovered that the anchors work properly when in a subquery, but not when in a main query. I hope that helps narrow it down.

@jwilder jwilder added this to the 1.2.1 milestone Feb 1, 2017
joelegasse added a commit that referenced this issue Feb 2, 2017
Fixes #7906

In an attempt to reduce the overhead of using regex for exact matches,
the query parser will replace `=~ /^thing$/` with `== 'thing'`, but the
conditions being checked would ignore if any flags were set on the
expression, so `=~ /(?i)^THING$/` was replaced with `== 'THING'`, which
will fail unless the case was already exact. This change ensures that no
flags have been changed from those defaulted by the parser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/influxql Issues related to InfluxQL query language kind/bug
Projects
None yet
Development

No branches or pull requests

3 participants