Merge pull request #5903 from influxdata/js-fix-point-sorting-for-distinct
Fix sorting for distinct by sorting by value when the point time is the samepull/5901/merge
commit
af01984480
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue