forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
180 lines (142 loc) · 3.13 KB
/
group.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package engine
type Group interface {
HasTimestamp() bool
GetTimestamp() int64
GetValue(int) interface{}
WithoutTimestamp() Group
WithTimestamp(int64) Group
}
type Group0 struct {
Group
}
var ALL_GROUP_IDENTIFIER = Group0{}
func (self Group0) HasTimestamp() bool {
return false
}
func (self Group0) GetTimestamp() int64 {
return 0
}
func (self Group0) GetValue(idx int) interface{} {
panic("invalid index")
}
func (self Group0) WithoutTimestamp() Group {
return self
}
func (self Group0) WithTimestamp(timestamp int64) Group {
return createGroup1(true, timestamp)
}
type Group1 struct {
hasTimestamp bool
value interface{}
}
func createGroup1(hasTimestamp bool, value interface{}) Group1 {
return Group1{hasTimestamp, value}
}
func (self Group1) HasTimestamp() bool {
return self.hasTimestamp
}
func (self Group1) GetTimestamp() int64 {
if self.hasTimestamp {
return self.value.(int64)
}
return 0
}
func (self Group1) GetValue(idx int) interface{} {
if idx != 0 {
panic("invalid index")
}
return self.value
}
func (self Group1) WithoutTimestamp() Group {
if self.hasTimestamp {
return ALL_GROUP_IDENTIFIER
}
return self
}
func (self Group1) WithTimestamp(timestamp int64) Group {
if self.hasTimestamp {
panic("This group has timestamp already")
}
return createGroup2(true, timestamp, self.value)
}
type Group2 struct {
hasTimestamp bool
value0 interface{}
value1 interface{}
}
func createGroup2(hasTimestamp bool, value0, value1 interface{}) Group2 {
return Group2{hasTimestamp, value0, value1}
}
func (self Group2) HasTimestamp() bool {
return self.hasTimestamp
}
func (self Group2) GetTimestamp() int64 {
if self.hasTimestamp {
return self.value0.(int64)
}
return 0
}
func (self Group2) WithoutTimestamp() Group {
if self.hasTimestamp {
return createGroup1(false, self.value1)
}
return self
}
func (self Group2) WithTimestamp(timestamp int64) Group {
if self.hasTimestamp {
panic("This group has timestamp already")
}
return createGroup3(true, timestamp, self.value0, self.value1)
}
func (self Group2) GetValue(idx int) interface{} {
switch idx {
case 0:
return self.value0
case 1:
return self.value1
default:
panic("invalid index")
}
}
type Group3 struct {
hasTimestamp bool
value0 interface{}
value1 interface{}
value2 interface{}
}
func createGroup3(hasTimestamp bool, value0, value1, value2 interface{}) Group3 {
return Group3{hasTimestamp, value0, value1, value2}
}
func (self Group3) HasTimestamp() bool {
return self.hasTimestamp
}
func (self Group3) GetTimestamp() int64 {
if self.hasTimestamp {
return self.value0.(int64)
}
return 0
}
func (self Group3) WithoutTimestamp() Group {
if self.hasTimestamp {
return createGroup1(false, self.value1)
}
return self
}
func (self Group3) WithTimestamp(timestamp int64) Group {
if self.hasTimestamp {
panic("This group has timestamp already")
}
panic("group with 4 columns isn't supported yet")
}
func (self Group3) GetValue(idx int) interface{} {
switch idx {
case 0:
return self.value0
case 1:
return self.value1
case 2:
return self.value2
default:
panic("invalid index")
}
}