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

[feature request] allow WHERE clause binary expressions on non-column values #3558

Closed
joshuawarner32 opened this issue Aug 5, 2015 · 6 comments

Comments

@joshuawarner32
Copy link

I've been trying to do various queries of the form SELECT * FROM the_series WHERE column1 / column2 > 0.5. Influxdb consistently gives me an "invalid expression" error. The particulars of the table and column layout aren't important; this happens everywhere I've tried queries of that form.

In fact, it happens for every WHERE clause expression in the form of a binary expression where neither side is itself a column reference. Digging around in the code, I can see this is the likely culprit: https://github.com/influxdb/influxdb/blob/master/tsdb/meta.go#L633

My questions are these: Is there a plan to remove that restriction? Would it be difficult? Would a PR be accepted? Where do I start?

Thanks.

@beckettsean beckettsean changed the title WHERE clause binary expressions are very restrictive [feature request] allow WHERE clause binary expressions on non-column values Aug 19, 2015
@beckettsean
Copy link
Contributor

@joshuawarner32 I can't say how challenging it would be, but PRs are always welcome.

@dgnorton or @otoolep any thoughts on whether this is a reasonable thing for a community PR?

@otoolep
Copy link
Contributor

otoolep commented Aug 19, 2015

The specific problem with this is that @joshuawarner32 must want to perform division on tags. But tags are always stored as strings. Performing math is not possible.

@otoolep
Copy link
Contributor

otoolep commented Aug 19, 2015

I might be mistaken actually, I guess column1 and column2 refer to fields in the data?

@otoolep
Copy link
Contributor

otoolep commented Aug 19, 2015

If the references in the WHERE are fields in the values, it would be in principle possible to do this. It would not be trivial change and would ripple throughout much of the code.

@joshuawarner32
Copy link
Author

@otoolep - yes, column1 and column2 are numeric fields in the data - though, I confess, I'm very fuzzy on exactly what a "tag" is. I don't think I'm accidentally inserting data in string form, but I can't rule it out at this point.

[That] would ripple throughout much of the code.

Hmm. That doesn't sound promising. I may still take a stab at it, depending on what else I find on my plate.

@beckettsean beckettsean added this to the Longer term milestone Aug 25, 2015
@jsternberg jsternberg self-assigned this Apr 7, 2016
@jsternberg
Copy link
Contributor

I think this should currently be possible and the error is probably validation being too strict. I'm going to try it for a bit.

Throwing this into the 0.13 milestone temporarily. If it turns out to be more difficult than I originally expected, we may have to push it back, but I think it should be easily feasible with the new query engine.

@jsternberg jsternberg modified the milestones: 0.13.0, Longer term Apr 7, 2016
jsternberg added a commit that referenced this issue Apr 18, 2016
Binary math inside of a where condition was previously disallowed. Now,
these types of queries are just passed verbatim down to the underlying
query engine which can handle it.

We may want to revisit this when it comes to tags at some point as it
prevents the more efficient filtering of tags that a simple expression
allows, but it allows a query like this to be done:

    SELECT * FROM cpu WHERE value + 2 < 5

So while it can be better, this is a good initial implementation to
provide this functionality. There are very rare situations where a tag
may be used appropriately in one of these circumstances.

Fixes #3558.
jsternberg added a commit that referenced this issue Apr 19, 2016
Binary math inside of a where condition was previously disallowed. Now,
these types of queries are just passed verbatim down to the underlying
query engine which can handle it.

We may want to revisit this when it comes to tags at some point as it
prevents the more efficient filtering of tags that a simple expression
allows, but it allows a query like this to be done:

    SELECT * FROM cpu WHERE value + 2 < 5

So while it can be better, this is a good initial implementation to
provide this functionality. There are very rare situations where a tag
may be used appropriately in one of these circumstances.

Fixes #3558.
jsternberg added a commit that referenced this issue Apr 20, 2016
Binary math inside of a where condition was previously disallowed. Now,
these types of queries are just passed verbatim down to the underlying
query engine which can handle it.

We may want to revisit this when it comes to tags at some point as it
prevents the more efficient filtering of tags that a simple expression
allows, but it allows a query like this to be done:

    SELECT * FROM cpu WHERE value + 2 < 5

So while it can be better, this is a good initial implementation to
provide this functionality. There are very rare situations where a tag
may be used appropriately in one of these circumstances.

Fixes #3558.
jsternberg added a commit that referenced this issue Apr 22, 2016
Binary math inside of a where condition was previously disallowed. Now,
these types of queries are just passed verbatim down to the underlying
query engine which can handle it.

We may want to revisit this when it comes to tags at some point as it
prevents the more efficient filtering of tags that a simple expression
allows, but it allows a query like this to be done:

    SELECT * FROM cpu WHERE value + 2 < 5

So while it can be better, this is a good initial implementation to
provide this functionality. There are very rare situations where a tag
may be used appropriately in one of these circumstances.

Fixes #3558.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants