Commit Graph

83 Commits (b8ef792606d2712907a23fd326db31b8de5e0de2)

Author SHA1 Message Date
Jonathan A. Sternberg 6afc2a77a5 Implement cumulative_sum() function
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)
2016-10-07 10:11:53 -05:00
Jonathan A. Sternberg 0b94f5dc1a Skip past points at the same time in derivative call within a merged series
The derivative() call would panic if it received two points at the same
time because it tried to divide by zero. The derivative call now skips
past these points. To avoid skipping past these points, use `GROUP BY *`
so that each series is kept separated into their own series.

The difference() call has also been modified to skip past these points.
Even though difference doesn't divide by the time, difference is
supposed to perform the same as derivative, but without dividing by the
time.
2016-09-13 16:57:36 -05:00
Jonathan A. Sternberg 252cde1e81 Fix golint errors for the influxql package 2016-06-20 08:51:02 -05:00
Nathaniel Cook 01aa9073b6 check for NaNs and do not return them 2016-06-03 10:51:46 -06:00
Nathaniel Cook 9314ae8e80 fix overflow in window iterator and holt winters roundTime 2016-05-27 11:07:50 +01:00
Nathaniel Cook 6ed0d94343 Add Holt-Winters forecasting method. 2016-05-19 09:24:56 -06:00
Jonathan A. Sternberg 9b6d5dfd78 Allow derivative() function to be used with ORDER BY desc
The derivative function had an arbitrary limitation that would cause it
to set the value to zero if the previous value was after the next value.
This caused all `ORDER BY desc` queries with `derivative()` to always
return zero values.

Fixes #4675.
2016-04-22 12:20:32 -04:00
Jonathan A. Sternberg 86046bb2d0 Implement derivatives across intervals for aggregate queries
For aggregate queries, derivatives will now alter the start time to one
interval behind and will use that interval to find the derivative of the
first point instead of giving no value for that interval. Null values
will still be discarded so if the interval before the one you are
querying is null, then it will be discarded like if it were in the
middle of the query. You can use `fill(0)` to fill in these values.

This does not apply to raw queries yet.

Also modified the derivative and difference aggregates to use the stream
iterator instead of the reduce slice iterator for space efficiency.

Fixes #3247. Contributes to #5943.
2016-04-15 18:16:08 -04:00
Jonathan A. Sternberg 6453dbc249 Implement simple moving average
The simple moving average will gradually emit points instead of waiting
until the end. This should apply to derivative and difference in the
future too.

Fixes #6112.
2016-03-29 14:36:43 -04:00
Jonathan A. Sternberg 9c5bc8ab2b Refactor reduce slice func to use the aggregator and emitter 2016-03-07 13:25:45 -05:00
Jonathan A. Sternberg 9113839e4c Fix sorting of `first()` and `last()` calls across shards
Previously the call iterator would normalize the time to the interval
for all calls. This meant that when `first()` or `last()` was called
with no group by interval the value would be found for each shard, the
time was normalized, then it tried to find the value between the shards
(but no longer with any time data as that had already been eliminated).

This removes part of the time logic from the call iterators and makes a
new iterator `IntervalIterator` to normalize the times as they come out
of the underlying iterator.

Fixes #5890.
2016-03-03 21:15:43 -05:00
Jonathan A. Sternberg 1c543b28a9 Refactored call iterators to make them public and more usable as a library
This refactor is primarily to support Kapacitor. Kapacitor doesn't care
about the iterators and mostly keeps the points it handles in memory.
The iterator interface is more than Kapacitor cares about.

This commit refactors and opens up the internals of aggregating and
reducing incoming points so it can be used by an outside library with
the same code. It also makes the iterators used by the call iterators
publically usable with new functionality.

Reducers are split into two methods which are separate interfaces that
can be combined for dealing with casting between different types. The
Aggregator interfaces accept points into the aggregator and retain any
internal state they need. The Emitter interface will then create a point
from that aggregated state which can be fed to the iterator. The
Emitters do not fill in the name or tag of the point as that is expected
to be done by the person aggregating the point. While the Emitters do
sometimes fill in the time, that value will also be overwritten by the
iterator. Filling in the time is to allow a future version that will
allow returning the point time instead of just the interval time.
2016-03-02 16:10:49 -05:00
Daniel Morsing 66fc270d1e Move aggregate funcs into tsdb
Pure move, No functional changes.
2015-09-11 14:27:47 +00:00
Cory LaNou fa4415b3a4 refactor processing top/bottom results. clarify some comments 2015-09-04 13:30:43 -05:00
Cory LaNou 4a9e936858 minor comment fix 2015-09-04 13:30:42 -05:00
Cory LaNou 3ca93594c3 BucketTime -> TMin 2015-09-04 13:30:42 -05:00
Cory LaNou 3db5a85139 all tests passing for top 2015-09-04 13:30:41 -05:00
Cory LaNou 347ffc70b4 wire up advanced top sorting/slicing 2015-09-04 13:30:41 -05:00
Cory LaNou 6f7eca9778 correcting sort behavior for top 2015-09-04 13:30:40 -05:00
Cory LaNou 046282249a wip remapping top output 2015-09-04 13:30:40 -05:00
Cory LaNou d060f3aba9 move all aggregate validations to the parser validation from map/reduce functions 2015-09-04 13:30:40 -05:00
Cory LaNou c5358dcd2a always sort results for ReduceTop. Skip test until we verify expected behavior 2015-09-04 13:30:40 -05:00
Cory LaNou b45872c1ac first pass at ReduceTop 2015-09-04 13:30:40 -05:00
Cory LaNou 6b005af731 change ReducePercentile signature 2015-09-04 13:30:40 -05:00
Cory LaNou e6de6d0887 change percentile to check errors in parsing, not in mapping 2015-09-04 13:30:40 -05:00
Cory LaNou f8d486f99c maptop bool test 2015-09-04 13:30:40 -05:00
Cory LaNou dd278a10f6 add test for mixed numerics and fix infer 2015-09-04 13:30:39 -05:00
Cory LaNou 193fd501db first pass at MapTop. more testing to come 2015-09-04 13:30:39 -05:00
Cory LaNou 72fd115dc2 exposing tags on cursors, top/bottom are valid funcs now 2015-09-04 13:30:39 -05:00
Daniel Morsing c4092d7fc3 Revert "move aggregate functions" 2015-09-02 10:47:58 -07:00
Daniel Morsing 65340a023b Move aggregate funcs into tsdb
Pure move, No functional changes.
2015-09-01 14:25:59 -07:00
Paul Dix 040fa060df Add more detailed logging for compactions 2015-09-01 09:52:20 -04:00
Daniel Morsing 8ca8293d11 only look at the first values for first()
Since we set up the aggregate queries so that iterator is ordered,
we only need to look at the first value. This cuts about 10 seconds
off a large single series query running first.
2015-08-31 13:43:28 -07:00
Philip 45cc51edfe During first() and last(), break any tie by value
If 2 or more points during this map-and-reduce share the same timestamp,
the tie is broken by looking at the value. This ensures that these
functions operate in a deterministic manner.

This solution due to @jwilder
2015-08-25 22:26:03 -07:00
Philip O'Toole 42b4a0b8bf string return is totally unused 2015-07-22 02:55:13 -07:00
Philip O'Toole 45dcf9960c Optimize the very inner loop of cursor iteration
This change moves tracking of next timestamp and values to simple
slices, as performance measurement showed that Peek() on TagSet cursors
was a huge performance drain. There is much more that can be done here,
but with this in place query performance has been restored to 0.9.1
levels.

This change also uses -1 to indicate that no value is available for a
given timestamp.
2015-07-22 02:55:09 -07:00
Alexander Morozov 675eacbf2c Fix style issues with else
In go it's better to just continue flow without "else", if it is return in
"if" statement.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
2015-07-17 11:10:23 -07:00
Joseph Crail 5fccee3d16 Fix spelling errors in comments and strings. 2015-06-28 02:54:34 -04:00
linfangrong a2c31264e4 Update functions.go 2015-06-11 19:45:05 +08:00
David Norton 843ef41cc9 fix #2845: fix panic on aggregate functions 2015-06-09 18:29:54 -04:00
Paul Dix 072dacc1ab Update tx.go to work with tsdb 2015-05-29 14:59:57 -06:00
Cory LaNou 8d17c01b20 make select count(distinct(field)) work 2015-05-19 13:15:14 -06:00
Cory LaNou 28d53b644f first pass at count distinct 2015-05-19 12:29:39 -06:00
Cory LaNou 97aa735bf1 fix comment type 2015-05-19 09:16:20 -06:00
Levi Cook e8b0484859 MapDistinct return nil on empty input and TestReduceDistinct 2015-05-19 09:16:20 -06:00
Levi Cook 8d4c36c9f6 MapDistinct and distinctValues sort tests 2015-05-19 09:16:20 -06:00
Levi Cook 41775a54eb map distinct and reduce cleanup 2015-05-19 09:16:20 -06:00
Levi Cook 514dd51bc6 refactor distinctValues sorting 2015-05-19 09:16:19 -06:00
Cory LaNou 81c9c9d681 use a concrete type for distinct results from mapper 2015-05-19 09:16:19 -06:00
Cory LaNou adc0e55a15 assing -> assign 2015-05-19 09:16:19 -06:00