diff --git a/influxql/call_iterator.go b/influxql/call_iterator.go index 97bb3c1614..332fab2d8d 100644 --- a/influxql/call_iterator.go +++ b/influxql/call_iterator.go @@ -658,7 +658,7 @@ func newFloatTopReduceSliceFunc(n int, tags []int, interval Interval) floatReduc points[i].Time = opt.startTime } } else { - sort.Stable(floatPoints(points)) + sort.Stable(floatPointsByTime(points)) } return points } @@ -704,7 +704,7 @@ func newIntegerTopReduceSliceFunc(n int, tags []int, interval Interval) integerR points[i].Time = opt.startTime } } else { - sort.Stable(integerPoints(points)) + sort.Stable(integerPointsByTime(points)) } return points } @@ -762,7 +762,7 @@ func newFloatBottomReduceSliceFunc(n int, tags []int, interval Interval) floatRe points[i].Time = opt.startTime } } else { - sort.Stable(floatPoints(points)) + sort.Stable(floatPointsByTime(points)) } return points } @@ -808,7 +808,7 @@ func newIntegerBottomReduceSliceFunc(n int, tags []int, interval Interval) integ points[i].Time = opt.startTime } } else { - sort.Stable(integerPoints(points)) + sort.Stable(integerPointsByTime(points)) } return points } diff --git a/influxql/iterator.gen.go b/influxql/iterator.gen.go index b94a23c039..25caded0e3 100644 --- a/influxql/iterator.gen.go +++ b/influxql/iterator.gen.go @@ -2274,7 +2274,7 @@ func (itr *integerReduceSliceIterator) reduce() []IntegerPoint { // integerReduceSliceFunc is the function called by a IntegerPoint slice reducer. type integerReduceSliceFunc func(a []IntegerPoint, opt *reduceOptions) []IntegerPoint -// integerTransformIterator executes a function to modify an existing point for every +// integerReduceIterator executes a function to modify an existing point for every // output of the input iterator. type integerTransformIterator struct { input IntegerIterator @@ -2298,30 +2298,6 @@ func (itr *integerTransformIterator) Next() *IntegerPoint { // new point if possible. type integerTransformFunc func(p *IntegerPoint) *IntegerPoint -// integerFloatTransformIterator executes a function to modify an existing point for every -// output of the input iterator. -type integerFloatTransformIterator struct { - input IntegerIterator - fn integerFloatTransformFunc -} - -// Close closes the iterator and all child iterators. -func (itr *integerFloatTransformIterator) Close() error { return itr.input.Close() } - -// Next returns the minimum value for the next available interval. -func (itr *integerFloatTransformIterator) Next() *FloatPoint { - p := itr.input.Next() - if p != nil { - return itr.fn(p) - } - return nil -} - -// integerFloatTransformFunc creates or modifies a point. -// The point passed in may be modified and returned rather than allocating a -// new point if possible. -type integerFloatTransformFunc func(p *IntegerPoint) *FloatPoint - // integerReduceIterator executes a function to modify an existing point for every // output of the input iterator. type integerBoolTransformIterator struct { diff --git a/influxql/iterator.go b/influxql/iterator.go index b89400df82..9f9794f5d6 100644 --- a/influxql/iterator.go +++ b/influxql/iterator.go @@ -951,6 +951,30 @@ type nilFloatIterator struct{} func (*nilFloatIterator) Close() error { return nil } func (*nilFloatIterator) Next() *FloatPoint { return nil } +// integerFloatTransformIterator executes a function to modify an existing point for every +// output of the input iterator. +type integerFloatTransformIterator struct { + input IntegerIterator + fn integerFloatTransformFunc +} + +// Close closes the iterator and all child iterators. +func (itr *integerFloatTransformIterator) Close() error { return itr.input.Close() } + +// Next returns the minimum value for the next available interval. +func (itr *integerFloatTransformIterator) Next() *FloatPoint { + p := itr.input.Next() + if p != nil { + return itr.fn(p) + } + return nil +} + +// integerFloatTransformFunc creates or modifies a point. +// The point passed in may be modified and returned rather than allocating a +// new point if possible. +type integerFloatTransformFunc func(p *IntegerPoint) *FloatPoint + type integerFloatCastIterator struct { input IntegerIterator } diff --git a/influxql/point.gen.go b/influxql/point.gen.go index 517bd3e13e..768eba6508 100644 --- a/influxql/point.gen.go +++ b/influxql/point.gen.go @@ -86,9 +86,14 @@ func decodeFloatPoint(pb *internal.Point) *FloatPoint { // floatPoints represents a slice of points sortable by value. type floatPoints []FloatPoint -func (a floatPoints) Len() int { return len(a) } -func (a floatPoints) Less(i, j int) bool { return a[i].Time < a[j].Time } -func (a floatPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a floatPoints) Len() int { return len(a) } +func (a floatPoints) Less(i, j int) bool { + if a[i].Time != a[j].Time { + return a[i].Time < a[j].Time + } + return a[i].Value < a[j].Value +} +func (a floatPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // floatPointsByValue represents a slice of points sortable by value. type floatPointsByValue []FloatPoint @@ -99,6 +104,13 @@ func (a floatPointsByValue) Less(i, j int) bool { return a[i].Value < a[j].Value func (a floatPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +// floatPointsByTime represents a slice of points sortable by value. +type floatPointsByTime []FloatPoint + +func (a floatPointsByTime) Len() int { return len(a) } +func (a floatPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } +func (a floatPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + // floatPointByFunc represents a slice of points sortable by a function. type floatPointsByFunc struct { points []FloatPoint @@ -262,9 +274,14 @@ func decodeIntegerPoint(pb *internal.Point) *IntegerPoint { // integerPoints represents a slice of points sortable by value. type integerPoints []IntegerPoint -func (a integerPoints) Len() int { return len(a) } -func (a integerPoints) Less(i, j int) bool { return a[i].Time < a[j].Time } -func (a integerPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a integerPoints) Len() int { return len(a) } +func (a integerPoints) Less(i, j int) bool { + if a[i].Time != a[j].Time { + return a[i].Time < a[j].Time + } + return a[i].Value < a[j].Value +} +func (a integerPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // integerPointsByValue represents a slice of points sortable by value. type integerPointsByValue []IntegerPoint @@ -275,6 +292,13 @@ func (a integerPointsByValue) Less(i, j int) bool { return a[i].Value < a[j].Val func (a integerPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +// integerPointsByTime represents a slice of points sortable by value. +type integerPointsByTime []IntegerPoint + +func (a integerPointsByTime) Len() int { return len(a) } +func (a integerPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } +func (a integerPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + // integerPointByFunc represents a slice of points sortable by a function. type integerPointsByFunc struct { points []IntegerPoint @@ -438,9 +462,14 @@ func decodeStringPoint(pb *internal.Point) *StringPoint { // stringPoints represents a slice of points sortable by value. type stringPoints []StringPoint -func (a stringPoints) Len() int { return len(a) } -func (a stringPoints) Less(i, j int) bool { return a[i].Time < a[j].Time } -func (a stringPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a stringPoints) Len() int { return len(a) } +func (a stringPoints) Less(i, j int) bool { + if a[i].Time != a[j].Time { + return a[i].Time < a[j].Time + } + return a[i].Value < a[j].Value +} +func (a stringPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // stringPointsByValue represents a slice of points sortable by value. type stringPointsByValue []StringPoint @@ -451,6 +480,13 @@ func (a stringPointsByValue) Less(i, j int) bool { return a[i].Value < a[j].Valu func (a stringPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +// stringPointsByTime represents a slice of points sortable by value. +type stringPointsByTime []StringPoint + +func (a stringPointsByTime) Len() int { return len(a) } +func (a stringPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } +func (a stringPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + // stringPointByFunc represents a slice of points sortable by a function. type stringPointsByFunc struct { points []StringPoint @@ -614,9 +650,14 @@ func decodeBooleanPoint(pb *internal.Point) *BooleanPoint { // booleanPoints represents a slice of points sortable by value. type booleanPoints []BooleanPoint -func (a booleanPoints) Len() int { return len(a) } -func (a booleanPoints) Less(i, j int) bool { return a[i].Time < a[j].Time } -func (a booleanPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a booleanPoints) Len() int { return len(a) } +func (a booleanPoints) Less(i, j int) bool { + if a[i].Time != a[j].Time { + return a[i].Time < a[j].Time + } + return !a[i].Value +} +func (a booleanPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // booleanPointsByValue represents a slice of points sortable by value. type booleanPointsByValue []BooleanPoint @@ -627,6 +668,13 @@ func (a booleanPointsByValue) Less(i, j int) bool { return !a[i].Value } func (a booleanPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +// booleanPointsByTime represents a slice of points sortable by value. +type booleanPointsByTime []BooleanPoint + +func (a booleanPointsByTime) Len() int { return len(a) } +func (a booleanPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } +func (a booleanPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + // booleanPointByFunc represents a slice of points sortable by a function. type booleanPointsByFunc struct { points []BooleanPoint diff --git a/influxql/point.gen.go.tmpl b/influxql/point.gen.go.tmpl index 648dc9d96d..97021f9d71 100644 --- a/influxql/point.gen.go.tmpl +++ b/influxql/point.gen.go.tmpl @@ -90,9 +90,14 @@ func decode{{.Name}}Point(pb *internal.Point) *{{.Name}}Point { // {{.name}}Points represents a slice of points sortable by value. type {{.name}}Points []{{.Name}}Point -func (a {{.name}}Points) Len() int { return len(a) } -func (a {{.name}}Points) Less(i, j int) bool { return a[i].Time < a[j].Time } -func (a {{.name}}Points) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a {{.name}}Points) Len() int { return len(a) } +func (a {{.name}}Points) Less(i, j int) bool { + if a[i].Time != a[j].Time { + return a[i].Time < a[j].Time + } + return {{if ne .Name "Boolean"}}a[i].Value < a[j].Value{{else}}!a[i].Value{{end}} +} +func (a {{.name}}Points) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // {{.name}}PointsByValue represents a slice of points sortable by value. type {{.name}}PointsByValue []{{.Name}}Point @@ -105,6 +110,13 @@ func (a {{.name}}PointsByValue) Less(i, j int) bool { return a[i].Value < a[j].V {{end}} func (a {{.name}}PointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +// {{.name}}PointsByTime represents a slice of points sortable by value. +type {{.name}}PointsByTime []{{.Name}}Point + +func (a {{.name}}PointsByTime) Len() int { return len(a) } +func (a {{.name}}PointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } +func (a {{.name}}PointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + // {{.name}}PointByFunc represents a slice of points sortable by a function. type {{.name}}PointsByFunc struct { points []{{.Name}}Point