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

Update Derivative for PositionPoint objects #5000

Merged
merged 2 commits into from
Dec 7, 2015
Merged

Conversation

nathanielc
Copy link
Contributor

The selectors that return PositionPoint were broken. Added logic to convert PositionPoint objects to float64. This fixes #4849.

I added integration tests for derivative functions with all other valid functions.

One variation doesn't work and I am curious if my test is correct or not.
A count query with fill previous doesn't work as expected since a group by interval with no points has a well defined count of 0. So the fill logic never sees a nil value to fill in with the previous value.

Give a query: SELECT derivative(count(value)) from db0.rp0.cpu where time >= '2010-07-01 18:47:00' and time <= '2010-07-01 18:47:03' group by time(2s) fill(previous)

With a dataset that is missing a all data points for a 2s interval the count returns 0 so the fill(previous) doesn't work and the derivative goes negative.

@corylanou @pauldix Thoughts on whether count with group by should return 0 or nil?

name: "calculate derivative of count with unit 4s group by time with fill previous",
command: `SELECT derivative(count(value), 4s) from db0.rp0.cpu where time >= '2010-07-01 18:47:00' and time <= '2010-07-01 18:47:03' group by time(2s) fill(previous)`,
exp: `{"results":[{"series":[{"name":"cpu","columns":["time","derivative"],"values":[["2010-07-01T18:47:02Z",0]]}]}]}`,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the failing count + derivative test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With my latest commit this is now passing, by explicitly using fill for count 0 time buckets.

@pauldix
Copy link
Member

pauldix commented Dec 5, 2015

looks good. Count should return 0. I think either fill shouldn't work on count, or fill should fill in any zero values on count. Nil and 0 are the same with a count query. What you think?

@nathanielc
Copy link
Contributor Author

I think fill should fill in any zeros on Count. I'll see how easy that is to get working.

@corylanou
Copy link
Contributor

I vote that count returns nil (or nothing) like all other aggregates do, and if you want it filled, you use fill like all other aggregates. This keeps everything consistent, plus makes it very easy for derivative to do the correct thing as well.

@pauldix
Copy link
Member

pauldix commented Dec 5, 2015

Count returning nil was actually a bug that we recently fixed. For other aggregates it makes sense to return nil, but not with count. Count is always defined. If there are no data points, it's zero.

@otoolep
Copy link
Contributor

otoolep commented Dec 5, 2015

https://github.com/influxdb/influxdb/pull/4778/files was the fix for count that @pauldix mentioned.

@nathanielc nathanielc force-pushed the nc-issue#4849 branch 2 times, most recently from f97e7af to 2011966 Compare December 7, 2015 17:24
// They're either filling with previous values or a specific number
for i, vals := range results {
// start at 1 because the first value is always time
for j := 1; j < len(vals); j++ {
if vals[j] == nil {
if vals[j] == nil || (isCount && isZero(vals[j])) {
switch e.stmt.Fill {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the logic for filling zero count values.

@corylanou @pauldix Thoughts?

@corylanou
Copy link
Contributor

Generally looks good. I would like to see a test with count(distinct value) in a derivative call and see it fail to make sure the check is working properly. Otherwise +1.

@nathanielc
Copy link
Contributor Author

@corylanou not sure I follow which test case you want. Something like this:

SELECT derivative(count(distinct(value))) FROM xxxx fill(previous)

Fails with an error about the query not containing a field before any of the fill logic can be evaluated. The code doesn't understand triply nested functions as far as I can tell.

name: "calculate derivative of count of distinct with unit default (4s) group by time with fill previous",
command: `SELECT derivative(count(distinct(value))) from db0.rp0.position where time >= '2010-07-01 18:47:00' and time <= '2010-07-01 18:47:07' group by time(4s) fill(previous)`,
exp: `{"results":[{"error":"aggregate call didn't contain a field derivative(count(distinct(value)))"}]}`,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Triple nested function fail check.

@corylanou
Copy link
Contributor

:shipit:

nathanielc pushed a commit that referenced this pull request Dec 7, 2015
Update Derivative for PositionPoint objects
@nathanielc nathanielc merged commit ae4140d into master Dec 7, 2015
@nathanielc nathanielc deleted the nc-issue#4849 branch December 7, 2015 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[0.9.5-rc3] (regression) Derivative does not work with MIN/MAX/LAST
4 participants