forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
65 lines (54 loc) · 1.18 KB
/
util.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package influxdb
import (
"fmt"
"code.google.com/p/log4go"
)
type TimePrecision int
const (
MicrosecondPrecision TimePrecision = iota
MillisecondPrecision
SecondPrecision
)
func parseTimePrecision(s string) (TimePrecision, error) {
switch s {
case "u":
return MicrosecondPrecision, nil
case "m":
log4go.Warn("time_precision=m will be disabled in future release, use time_precision=ms instead")
fallthrough
case "ms":
return MillisecondPrecision, nil
case "s":
return SecondPrecision, nil
case "":
return MillisecondPrecision, nil
}
return 0, fmt.Errorf("Unknown time precision %s", s)
}
func hasDuplicates(ss []string) bool {
m := make(map[string]struct{}, len(ss))
for _, s := range ss {
if _, ok := m[s]; ok {
return true
}
m[s] = struct{}{}
}
return false
}
func removeField(fields []string, name string) []string {
index := -1
for idx, field := range fields {
if field == name {
index = idx
break
}
}
if index == -1 {
return fields
}
return append(fields[:index], fields[index+1:]...)
}
func removeTimestampFieldDefinition(fields []string) []string {
fields = removeField(fields, "time")
return removeField(fields, "sequence_number")
}