forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_by.go
46 lines (40 loc) · 1.12 KB
/
group_by.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package parser
import (
"bytes"
"common"
"fmt"
"time"
)
type GroupByClause struct {
FillWithZero bool
FillValue *Value
Elems []*Value
}
func (self GroupByClause) GetGroupByTime() (*time.Duration, error) {
for _, groupBy := range self.Elems {
if groupBy.IsFunctionCall() {
// TODO: check the number of arguments and return an error
if len(groupBy.Elems) != 1 {
return nil, common.NewQueryError(common.WrongNumberOfArguments, "time function only accepts one argument")
}
// TODO: check the function name
// TODO: error checking
arg := groupBy.Elems[0].Name
durationInt, err := common.ParseTimeDuration(arg)
if err != nil {
return nil, common.NewQueryError(common.InvalidArgument, fmt.Sprintf("invalid argument %s to the time function", arg))
}
duration := time.Duration(durationInt)
return &duration, nil
}
}
return nil, nil
}
func (self *GroupByClause) GetString() string {
buffer := bytes.NewBufferString("")
buffer.WriteString(Values(self.Elems).GetString())
if self.FillWithZero {
fmt.Fprintf(buffer, " fill(%s)", self.FillValue.GetString())
}
return buffer.String()
}