Skip to content

Commit

Permalink
export tsdb.Iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Sep 22, 2015
1 parent 07c9d40 commit 007508b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [#4065](https://github.com/influxdb/influxdb/pull/4065): Added precision support in cmd client. Thanks @sbouchex
- [#4140](https://github.com/influxdb/influxdb/pull/4140): Make storage engine configurable
- [#4161](https://github.com/influxdb/influxdb/pull/4161): Implement bottom selector function
- [#4196](https://github.com/influxdb/influxdb/pull/4196): Export tsdb.Iterator

### Bugfixes
- [#3457](https://github.com/influxdb/influxdb/issues/3457): [0.9.3] cannot select field names with prefix + "." that match the measurement name
Expand Down
34 changes: 17 additions & 17 deletions tsdb/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (

// iterator represents a forward-only iterator over a set of points.
// These are used by the mapFunctions in this file
type iterator interface {
type Iterator interface {
Next() (time int64, value interface{})
Tags() map[string]string
TMin() int64
}

// mapFunc represents a function used for mapping over a sequential series of data.
// The iterator represents a single group by interval
type mapFunc func(iterator) interface{}
type mapFunc func(Iterator) interface{}

// reduceFunc represents a function used for reducing mapper output.
type reduceFunc func([]interface{}) interface{}
Expand Down Expand Up @@ -78,7 +78,7 @@ func initializeMapFunc(c *influxql.Call) (mapFunc, error) {
case "last":
return MapLast, nil
case "top", "bottom":
return func(itr iterator) interface{} {
return func(itr Iterator) interface{} {
return MapTopBottom(itr, c)
}, nil
case "percentile":
Expand Down Expand Up @@ -213,7 +213,7 @@ func initializeUnmarshaller(c *influxql.Call) (unmarshalFunc, error) {
}

// MapCount computes the number of values in an iterator.
func MapCount(itr iterator) interface{} {
func MapCount(itr Iterator) interface{} {
n := float64(0)
for k, _ := itr.Next(); k != -1; k, _ = itr.Next() {
n++
Expand All @@ -238,7 +238,7 @@ func (d interfaceValues) Less(i, j int) bool {
}

// MapDistinct computes the unique values in an iterator.
func MapDistinct(itr iterator) interface{} {
func MapDistinct(itr Iterator) interface{} {
var index = make(map[interface{}]struct{})

for time, value := itr.Next(); time != -1; time, value = itr.Next() {
Expand Down Expand Up @@ -292,7 +292,7 @@ func ReduceDistinct(values []interface{}) interface{} {
}

// MapCountDistinct computes the unique count of values in an iterator.
func MapCountDistinct(itr iterator) interface{} {
func MapCountDistinct(itr Iterator) interface{} {
var index = make(map[interface{}]struct{})

for time, value := itr.Next(); time != -1; time, value = itr.Next() {
Expand Down Expand Up @@ -336,7 +336,7 @@ const (
)

// MapSum computes the summation of values in an iterator.
func MapSum(itr iterator) interface{} {
func MapSum(itr Iterator) interface{} {
n := float64(0)
count := 0
var resultType NumberType
Expand Down Expand Up @@ -391,7 +391,7 @@ func ReduceSum(values []interface{}) interface{} {
}

// MapMean computes the count and sum of values in an iterator to be combined by the reducer.
func MapMean(itr iterator) interface{} {
func MapMean(itr Iterator) interface{} {
out := &meanMapOutput{}

for k, v := itr.Next(); k != -1; k, v = itr.Next() {
Expand Down Expand Up @@ -597,7 +597,7 @@ type minMaxMapOut struct {
}

// MapMin collects the values to pass to the reducer
func MapMin(itr iterator) interface{} {
func MapMin(itr Iterator) interface{} {
min := &minMaxMapOut{}

pointsYielded := false
Expand Down Expand Up @@ -660,7 +660,7 @@ func ReduceMin(values []interface{}) interface{} {
}

// MapMax collects the values to pass to the reducer
func MapMax(itr iterator) interface{} {
func MapMax(itr Iterator) interface{} {
max := &minMaxMapOut{}

pointsYielded := false
Expand Down Expand Up @@ -728,7 +728,7 @@ type spreadMapOutput struct {
}

// MapSpread collects the values to pass to the reducer
func MapSpread(itr iterator) interface{} {
func MapSpread(itr Iterator) interface{} {
out := &spreadMapOutput{}
pointsYielded := false
var val float64
Expand Down Expand Up @@ -789,7 +789,7 @@ func ReduceSpread(values []interface{}) interface{} {
}

// MapStddev collects the values to pass to the reducer
func MapStddev(itr iterator) interface{} {
func MapStddev(itr Iterator) interface{} {
var values []float64

for k, v := itr.Next(); k != -1; k, v = itr.Next() {
Expand Down Expand Up @@ -847,7 +847,7 @@ type firstLastMapOutput struct {

// MapFirst collects the values to pass to the reducer
// This function assumes time ordered input
func MapFirst(itr iterator) interface{} {
func MapFirst(itr Iterator) interface{} {
k, v := itr.Next()
if k == -1 {
return nil
Expand Down Expand Up @@ -892,7 +892,7 @@ func ReduceFirst(values []interface{}) interface{} {
}

// MapLast collects the values to pass to the reducer
func MapLast(itr iterator) interface{} {
func MapLast(itr Iterator) interface{} {
out := &firstLastMapOutput{}
pointsYielded := false

Expand Down Expand Up @@ -1301,7 +1301,7 @@ func (m *mapIter) Next() (time int64, value interface{}) {
}

// MapTopBottom emits the top/bottom data points for each group by interval
func MapTopBottom(itr iterator, c *influxql.Call) interface{} {
func MapTopBottom(itr Iterator, c *influxql.Call) interface{} {
// Capture the limit if it was specified in the call
lit, _ := c.Args[len(c.Args)-1].(*influxql.NumberLiteral)
limit := int(lit.Val)
Expand Down Expand Up @@ -1440,7 +1440,7 @@ func ReduceTopBottom(values []interface{}, c *influxql.Call) interface{} {
}

// MapEcho emits the data points for each group by interval
func MapEcho(itr iterator) interface{} {
func MapEcho(itr Iterator) interface{} {
var values []interface{}

for k, v := itr.Next(); k != -1; k, v = itr.Next() {
Expand Down Expand Up @@ -1496,7 +1496,7 @@ func IsNumeric(c *influxql.Call) bool {
}

// MapRawQuery is for queries without aggregates
func MapRawQuery(itr iterator) interface{} {
func MapRawQuery(itr Iterator) interface{} {
var values []*rawQueryMapOutput
for k, v := itr.Next(); k != -1; k, v = itr.Next() {
val := &rawQueryMapOutput{k, v}
Expand Down

0 comments on commit 007508b

Please sign in to comment.