-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 cumulative_sum() function #7388
Conversation
Can you update the description with more details about the use of this function? |
d22f8d6
to
05ae3da
Compare
Updated the description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good.
I don't understand why we are skipping duplicate values. Why is that part of a cumulative sum? Do any other reducers skip duplicates?
} | ||
|
||
func (r *FloatCumulativeSumReducer) AggregateFloat(p *FloatPoint) { | ||
if !r.curr.Nil && r.curr.Time == p.Time { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this logic for? Skipping points in the sum that have the same time? What is the use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the other stream processors will skip points at the same time such as derivative()
and difference()
so I had this one do it too. It's to avoid having it emit multiple values at the same time. I can remove this though. I don't think I have the same thing with moving_average()
even though it's also a stream processor. Which do you think is more correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we shouldn't skip points in this case. The reason that derivative does it is it needs to use the elapsed time and it would create a divide by 0 otherwise. Since this is just a sum I would rather it simply sum the values and nothing else, similar to moving_avg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would concur with @nathanielc's logic here, if this is meant to be a 'wrapper' function to something like derivative anyway, let the derivative handle the dupes accordingly and simply sum up the reseults it presents. That should keep things easy.
// FloatCumulativeSumReducer cumulates the values from each point. | ||
type FloatCumulativeSumReducer struct { | ||
curr FloatPoint | ||
emitted bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emitted doesn't seem to be used anywhere, did I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emitted is used to skip points at the same time value. It is used in Emit()
.
05ae3da
to
fe10c3c
Compare
@nathanielc I updated this with your recommendation. Can you take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks
The `cumulative_sum()` function can be used to sum each new point and output the current total. For the following points: cpu value=2 0 cpu value=4 10 cpu value=6 20 This would output the following points: > SELECT cumulative_sum(value) FROM cpu time value ---- ----- 0 2 10 6 20 12 As can be seen, each new point adds to the sum of the previous point and outputs the value with the same timestamp. The function can also be used with an aggregate like `derivative()`. > SELECT cumulative_sum(mean(value) FROM cpu WHERE time >= now() - 10m GROUP BY time(1m)
fe10c3c
to
6afc2a7
Compare
The
cumulative_sum()
function can be used to sum each new point andoutput the current total. For the following points:
This would output the following points:
As can be seen, each new point adds to the sum of the previous point and
outputs the value with the same timestamp.
The function can also be used with an aggregate like
derivative()
.