forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coerce_values.go
69 lines (58 loc) · 1.67 KB
/
coerce_values.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
66
67
68
69
package common
import (
"github.com/influxdb/influxdb/protocol"
)
func getValue(value *protocol.FieldValue) (interface{}, Type) {
if value.Int64Value != nil {
return value.Int64Value, TYPE_INT
}
if value.DoubleValue != nil {
return value.DoubleValue, TYPE_DOUBLE
}
if value.BoolValue != nil {
return value.BoolValue, TYPE_BOOL
}
if value.StringValue != nil {
return value.StringValue, TYPE_STRING
}
return nil, TYPE_UNKNOWN
}
func CoerceValues(leftValue, rightValue *protocol.FieldValue) (interface{}, interface{}, Type) {
if leftValue == nil {
value, t := getValue(rightValue)
return nil, value, t
}
if rightValue == nil {
value, t := getValue(leftValue)
return value, nil, t
}
if leftValue.Int64Value != nil {
if rightValue.Int64Value != nil {
return *leftValue.Int64Value, *rightValue.Int64Value, TYPE_INT
} else if rightValue.DoubleValue != nil {
return float64(*leftValue.Int64Value), *rightValue.DoubleValue, TYPE_DOUBLE
}
return nil, nil, TYPE_UNKNOWN
}
if leftValue.DoubleValue != nil {
if rightValue.Int64Value != nil {
return *leftValue.DoubleValue, float64(*rightValue.Int64Value), TYPE_DOUBLE
} else if rightValue.DoubleValue != nil {
return *leftValue.DoubleValue, *rightValue.DoubleValue, TYPE_DOUBLE
}
return nil, nil, TYPE_UNKNOWN
}
if leftValue.StringValue != nil {
if rightValue.StringValue == nil {
return nil, nil, TYPE_UNKNOWN
}
return *leftValue.StringValue, *rightValue.StringValue, TYPE_STRING
}
if leftValue.BoolValue != nil {
if rightValue.BoolValue == nil {
return nil, nil, TYPE_BOOL
}
return *leftValue.BoolValue, *rightValue.BoolValue, TYPE_BOOL
}
return nil, nil, TYPE_UNKNOWN
}