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] DOT aggregate functionality or arithmetic inside of aggregates #5095

Closed
amancevice opened this issue Dec 11, 2015 · 13 comments

Comments

@amancevice
Copy link

It would be nice if InfluxDB offered a dot-product functionality, specifically for continuous queries. Something like:

SELECT DOT(valueA, valueB) FROM my_measurement WHERE time>now()-1h AND time<now()
@hillar
Copy link

hillar commented Dec 12, 2015

Do you mean
"dot-product functionality" === if vector valueA is perpendicular with vector valueB, then the dot product is equal to zero

R> a <- c(1,2,3,4,5) 
R> b <- c(2,4,6,8,10) 
R> dot <- acos( sum(a*b,na.rm=TRUE) / ( sqrt(sum(a * a,na.rm=TRUE)) * sqrt(sum(b * b,na.rm=TRUE)) ) ) 
R> dot
[1] 0

@amancevice
Copy link
Author

Yes that is correct, although I admit I don't really follow your example in R. I'm looking for something similar to numpy.dot() for Python. So,

In [1]: import numpy

In [2]: a = 1, 2, 3, 4, 5

In [3]: b = 2, 4, 6, 8, 10

In [4]: dot = numpy.dot(a, b)

In [5]: dot
Out[5]: 110

@desa
Copy link
Contributor

desa commented Dec 14, 2015

@amancevice both valueA and valueB are scalars. InfluxDB doesn't allow you to store vectors or arrays.

@amancevice
Copy link
Author

@mjdesa Apologies I must not be explaining myself. Say I have a query that looks like this:

SELECT DOT(valueA, valueB) AS dot FROM my_measurement GROUP BY time(1d)

I would expect InfluxDB to select valueA and valueB from the measurement, group them into 1d groups, and apply the aggregation DOT() on each group where the inputs are the columns, valueA and valueB.

So, if one of the groups in my series looked like this:

time                valueA valueB
1357088400000000000 1      2
1357088400000000000 2      4
1357088460000000000 3      6
1357088520000000000 4      8
1357088520000000000 5      10

I would expect the aggregate row to look like this:

time                dot
1357084800000000000 110

Does that make sense? Perhaps there is already a way to get this result but I thought including a DOT() function would be useful enough to include on its own.

@desa
Copy link
Contributor

desa commented Dec 14, 2015

@amancevice ah I see what you're saying.

Would the following query work?

SELECT sum(valueA * valueB) AS dot FROM my_measurement GROUP BY time(1d)

@amancevice
Copy link
Author

I get the following error trying SUM(valueA * valueB):

ERR: error parsing query: expected field argument in sum()

@desa
Copy link
Contributor

desa commented Dec 14, 2015

Ah thats a problem. Looks like we don't support arithmetic in aggregate functions.

@desa desa changed the title Request for DOT aggregate functionality [feature request] DOT aggregate functionality or arithmetic inside of aggregates Dec 14, 2015
@amancevice
Copy link
Author

Great, thanks for opening the feature request!

@amancevice
Copy link
Author

Any idea when this might make it into a release? The ability to do arithmetic in queries -- specifically I'm thinking of continuous queries -- is something of a deal-breaker for using InfluxDB in production.

@desa
Copy link
Contributor

desa commented Jan 14, 2016

@amancevice at the moment we're rewriting our query engine which will serve as the foundation for building out this sort of functionality. Once the query engine has been rewritten, we'd gladly accept a PR for the functionality you're looking for.

@amancevice
Copy link
Author

Sounds good

@beckettsean
Copy link
Contributor

As mentioned in my post to the mailing list we are experimenting with simplifying our open GitHub Issues. This feature request has been rolled into an aggregate issue for all function requests, so that we can close this issue until we are ready to work on it.

You may continue to make comments here. Closing the issue does not mean we are rejecting this idea.

@desa
Copy link
Contributor

desa commented May 5, 2016

@pauldix

jsternberg added a commit that referenced this issue May 18, 2017
The test cases demonstrate that the following issues are resolved
through some newer features.

Related to #813, #5095, #2467, #5345, and #5150.
stuartcarnie pushed a commit that referenced this issue May 25, 2017
The test cases demonstrate that the following issues are resolved
through some newer features.

Related to #813, #5095, #2467, #5345, and #5150.
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

4 participants