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

Implement basic trigonometry functions #9499

Merged
merged 1 commit into from
Mar 21, 2018

Conversation

jsternberg
Copy link
Contributor

@jsternberg jsternberg commented Feb 28, 2018

This adds support for math functions into the query language. Math
functions are special because they are transformations and do not access
the filesystem in the same way aggregate functions do. A transformation
takes one point and always outputs one point making it more similar to
binary expressions so these math functions follow the same rules as
binary expressions.

This also supports using math literals (so you can do sin(1)) and the
math functions can be used anywhere such as in a field or an expression.
Both of the following are supported:

SELECT sin(value) FROM cpu
SELECT value FROM cpu WHERE sin(value) > 0.5

Arguments are in radians. Degrees is not supported.

Fixes #9424.

@ghost ghost assigned jsternberg Feb 28, 2018
@ghost ghost added the review label Feb 28, 2018
@jsternberg jsternberg added this to the 1.6.0 milestone Feb 28, 2018
@jsternberg jsternberg force-pushed the js-9424-implement-trigonometry-functions branch from cefa3cb to db3fc6e Compare February 28, 2018 20:48
@jsternberg
Copy link
Contributor Author

I'm likely going to refactor this to make use of #9511 instead of doing custom iterators. I think it will use less code and offer greater flexibility so we can shortly follow this with sqrt(x) and pow(x, y) along with related trigonometry functions like atan2(x, y).

The idea is that all of these functions will be implemented in this project (the query package) and they would not be present in the influxql project. But, for that, we need to expose an interface there. influxdata/influxql#13 is for that.

@influxdata influxdata deleted a comment from hercules-influx Mar 13, 2018
@jsternberg jsternberg force-pushed the js-9424-implement-trigonometry-functions branch 3 times, most recently from d66eb15 to 5ae10be Compare March 14, 2018 21:04
This adds support for math functions into the query language. Math
functions are special because they are transformations and do not access
the filesystem in the same way aggregate functions do. A transformation
takes one point and always outputs one point making it more similar to
binary expressions so these math functions follow the same rules as
binary expressions.

This also supports using math literals (so you can do `sin(1)`) and the
math functions can be used anywhere such as in a field or an expression.
Both of the following are supported:

    SELECT sin(value) FROM cpu
    SELECT value FROM cpu WHERE sin(value) > 0.5

Arguments are in radians. Degrees is not supported.
@jsternberg jsternberg force-pushed the js-9424-implement-trigonometry-functions branch from 5ae10be to 6e627cf Compare March 20, 2018 19:14
@jsternberg
Copy link
Contributor Author

This has been refactored to make use of the math refactor in #9511. It's much simpler now and it will be easy to implement the other value transform iterators without advanced iterator nesting logic.

@jsternberg jsternberg requested a review from stuartcarnie March 20, 2018 19:18
Copy link
Contributor

@stuartcarnie stuartcarnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

@jsternberg jsternberg merged commit ea1e995 into master Mar 21, 2018
@ghost ghost removed the review label Mar 21, 2018
@jsternberg jsternberg deleted the js-9424-implement-trigonometry-functions branch March 21, 2018 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants