DRY and modify the code to be idiomatic
parent
cc5a5e86bd
commit
7b194318a2
|
@ -991,14 +991,15 @@ func (self *ModeAggregator) GetValues(state interface{}) [][]*protocol.FieldValu
|
||||||
counts = append(counts, count)
|
counts = append(counts, count)
|
||||||
countMap[count] = append(countMap[count], value)
|
countMap[count] = append(countMap[count], value)
|
||||||
}
|
}
|
||||||
sort.Ints(counts)
|
|
||||||
|
// descending sort
|
||||||
|
sort.Sort(sort.Reverse(sort.IntSlice(counts)))
|
||||||
|
|
||||||
returnValues := [][]*protocol.FieldValue{}
|
returnValues := [][]*protocol.FieldValue{}
|
||||||
|
|
||||||
last := 0
|
last := 0
|
||||||
for i := len(counts); i > 0; i-- {
|
for _, count := range counts {
|
||||||
// counts can contain duplicates, but we only want to append each count-set once
|
// counts can contain duplicates, but we only want to append each count-set once
|
||||||
count := counts[i-1]
|
|
||||||
if count == last {
|
if count == last {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1037,11 +1038,9 @@ func NewModeAggregator(_ *parser.SelectQuery, value *parser.Value, defaultValue
|
||||||
size := 1
|
size := 1
|
||||||
if len(value.Elems) == 2 {
|
if len(value.Elems) == 2 {
|
||||||
switch value.Elems[1].Type {
|
switch value.Elems[1].Type {
|
||||||
case parser.ValueInt, parser.ValueFloat:
|
case parser.ValueInt:
|
||||||
var err error
|
var err error
|
||||||
_size := int64(1)
|
size, err = strconv.Atoi(value.Elems[1].Name)
|
||||||
_size, err = strconv.ParseInt(value.Elems[1].Name, 10, 32)
|
|
||||||
size = int(_size)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, common.NewQueryError(common.InvalidArgument, "Cannot parse %s into an int", value.Elems[1].Name)
|
return nil, common.NewQueryError(common.InvalidArgument, "Cannot parse %s into an int", value.Elems[1].Name)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue