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

derivative node returns value from the future #1329

Closed
phemmer opened this issue Apr 17, 2017 · 4 comments
Closed

derivative node returns value from the future #1329

phemmer opened this issue Apr 17, 2017 · 4 comments
Labels

Comments

@phemmer
Copy link

phemmer commented Apr 17, 2017

The derivative() node computes the derivative between a point, and the one that follows it, but adds the calculated derivative value to the first point, not the second.
This is counterintuitive as this is not how a derivative is defined, nor is it how InfluxDB's derivative behaves.
Additionally the behavior results in the derivative() node buffering a point. If it behaved as expected, buffering would not be necessary.

foo v=1i 1000000000
foo v=2i 2000000000
foo v=4i 3000000000
foo v=8i 4000000000
foo v=16i 5000000000
stream|from().measurement('foo')|derivative('v').as('derivative')|log()

Expected:

"Fields":{"v":1},"Time":"1970-01-01T00:00:01Z"
"Fields":{"v":2,"derivative":1},"Time":"1970-01-01T00:00:02Z"
"Fields":{"v":4,"derivative":2},"Time":"1970-01-01T00:00:03Z"
"Fields":{"v":8,"derivative":4},"Time":"1970-01-01T00:00:04Z"
"Fields":{"v":16,"derivative":8},"Time":"1970-01-01T00:00:05Z"

Actual:

"Fields":{"v":1,"derivative":1},"Time":"1970-01-01T00:00:01Z"
"Fields":{"v":2,"derivative":2},"Time":"1970-01-01T00:00:02Z"
"Fields":{"v":4,"derivative":4},"Time":"1970-01-01T00:00:03Z"
"Fields":{"v":8,"derivative":8},"Time":"1970-01-01T00:00:04Z"
@phemmer
Copy link
Author

phemmer commented Apr 20, 2017

Another issue I just encountered with the derivative() node:

foo v=1i 1000000000
foo v=2i 2000000000
foo x=3i 2500000000
foo v=4i 3000000000
foo v=8i 4000000000
foo v=16i 5000000000
stream|from().measurement('foo')|derivative('v').as('derivative')|log()

Actual:

"Fields":{"derivative":1,"v":1},"Time":"1970-01-01T00:00:01Z"
"Fields":{"derivative":4,"v":4},"Time":"1970-01-01T00:00:03Z"
"Fields":{"derivative":8,"v":8},"Time":"1970-01-01T00:00:04Z"

Due to the original issue this was opened for, I expected a couple different things, but this output was not one of them. I can't make sense of what's going on here. Obviously we have a point where the v field is missing, so we can't use it to calculate a derivative. But what happened to the v=2i point? The derivative between the "v":1 and "v":4 point certainly isn't 1.

@nathanielc
Copy link
Contributor

@phemmer Looking through your examples I agree the actual behavior is quite confusing. We will take a look at the best way to fix this while minimizing any breaking changes to existing behavior.

@nathanielc nathanielc added the bug label Apr 20, 2017
@phemmer
Copy link
Author

phemmer commented Apr 20, 2017

I actually started work on this. Basically I just adjusted it so that the derivative is added to the latter point, not the former one, and the first point in the stream/batch is dropped (currently in batch the last point is dropped).
But I can abandon the work if you want to handle it yourself.

@nathanielc
Copy link
Contributor

Go ahead a put up a PR on what you have, we can start the discussion from there. Your solution sounds like what I was thinking.

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

No branches or pull requests

2 participants