@@ -17,6 +17,7 @@ limitations under the License.
17
17
package executor
18
18
19
19
import (
20
+ "bytes"
20
21
"testing"
21
22
22
23
"github.com/openGemini/openGemini/engine/hybridqp"
@@ -44,13 +45,13 @@ func TestIntegerFirstReduce(t *testing.T) {
44
45
chunk .AddColumn (c2 )
45
46
46
47
// first column
47
- idx , v , isNil := IntegerFirstReduce (chunk , 0 , 0 , 5 )
48
+ idx , v , isNil := FirstReduce [ int64 ] (chunk , chunk . Column ( 0 ). IntegerValues () , 0 , 0 , 5 )
48
49
if ! (idx == 0 && v == 1 && ! isNil ) {
49
50
t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
50
51
}
51
52
52
53
// second column
53
- idx , v , isNil = IntegerFirstReduce (chunk , 1 , 0 , 5 )
54
+ idx , v , isNil = FirstReduce [ int64 ] (chunk , chunk . Column ( 1 ). IntegerValues () , 1 , 0 , 5 )
54
55
if ! (idx == 0 && v == 11 && ! isNil ) {
55
56
t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
56
57
}
@@ -60,6 +61,7 @@ func TestFloatFirstReduce(t *testing.T) {
60
61
chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
61
62
influxql.VarRef {Val : "val_float1" , Type : influxql .Float },
62
63
influxql.VarRef {Val : "val_float2" , Type : influxql .Float },
64
+ influxql.VarRef {Val : "val_float3" , Type : influxql .Float },
63
65
influxql.VarRef {Val : "time" , Type : influxql .Integer },
64
66
), "test" )
65
67
@@ -71,22 +73,33 @@ func TestFloatFirstReduce(t *testing.T) {
71
73
c2 .AppendNilsV2 (true , true , true , true , true )
72
74
c2 .AppendFloatValues ([]float64 {11.1 , 18.2 , 19.3 , 20.4 , 21.5 })
73
75
76
+ c3 := NewColumnImpl (influxql .Float )
77
+ c3 .AppendNilsV2 (true , true , true , false , false )
78
+ c3 .AppendFloatValues ([]float64 {11.1 , 18.2 , 19.3 })
79
+
74
80
chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
75
81
chunk .ResetIntervalIndex (0 )
76
82
chunk .AddColumn (c1 )
77
83
chunk .AddColumn (c2 )
84
+ chunk .AddColumn (c3 )
78
85
79
86
// first column
80
- idx , v , isNil := FloatFirstReduce (chunk , 0 , 0 , 5 )
87
+ idx , v , isNil := FirstReduce [ float64 ] (chunk , chunk . Column ( 0 ). FloatValues () , 0 , 0 , 5 )
81
88
if ! (idx == 0 && v == 1.1 && ! isNil ) {
82
89
t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
83
90
}
84
91
85
92
// second column
86
- idx , v , isNil = FloatFirstReduce (chunk , 1 , 0 , 5 )
93
+ idx , v , isNil = FirstReduce [ float64 ] (chunk , chunk . Column ( 1 ). FloatValues () , 1 , 0 , 5 )
87
94
if ! (idx == 0 && v == 11.1 && ! isNil ) {
88
95
t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
89
96
}
97
+
98
+ // third column
99
+ idx , v , isNil = FirstReduce [float64 ](chunk , chunk .Column (2 ).FloatValues (), 2 , 4 , 5 )
100
+ if ! (idx == 4 && v == 0 && isNil ) {
101
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
102
+ }
90
103
}
91
104
92
105
func TestStringFirstReduce (t * testing.T ) {
@@ -109,12 +122,12 @@ func TestStringFirstReduce(t *testing.T) {
109
122
chunk .AddColumn (c1 )
110
123
chunk .AddColumn (c2 )
111
124
112
- idx , v , isNil := StringFirstReduce (chunk , 0 , 0 , 5 )
125
+ idx , v , isNil := FirstReduce [ string ] (chunk , chunk . Column ( 0 ). StringValuesV2 ( nil ) , 0 , 0 , 5 )
113
126
if ! (idx == 0 && v == "string1" && ! isNil ) {
114
127
t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
115
128
}
116
129
117
- idx , v , isNil = StringFirstReduce (chunk , 1 , 0 , 5 )
130
+ idx , v , isNil = FirstReduce [ string ] (chunk , chunk . Column ( 1 ). StringValuesV2 ( nil ) , 1 , 0 , 5 )
118
131
if ! (idx == 0 && v == "string11" && ! isNil ) {
119
132
t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
120
133
}
@@ -124,29 +137,219 @@ func TestBooleanFirstReduce(t *testing.T) {
124
137
chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
125
138
influxql.VarRef {Val : "val_bool1" , Type : influxql .Boolean },
126
139
influxql.VarRef {Val : "val_bool2" , Type : influxql .Boolean },
140
+ influxql.VarRef {Val : "val_bool3" , Type : influxql .Boolean },
127
141
influxql.VarRef {Val : "time" , Type : influxql .Integer },
128
142
), "test" )
129
143
130
144
c1 := NewColumnImpl (influxql .Boolean )
131
145
c1 .AppendNilsV2 (true , true , true , false , false )
132
146
c1 .AppendBooleanValues ([]bool {true , false , false })
133
147
134
- c2 := NewColumnImpl (influxql .Integer )
148
+ c2 := NewColumnImpl (influxql .Boolean )
135
149
c2 .AppendNilsV2 (true , true , true , true , true )
136
150
c2 .AppendBooleanValues ([]bool {false , true , true , true , true })
137
151
152
+ c3 := NewColumnImpl (influxql .Boolean )
153
+ c3 .AppendNilsV2 (true , true , true , false , false )
154
+ c3 .AppendBooleanValues ([]bool {false , true , true , true , true })
155
+
138
156
chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
139
157
chunk .ResetIntervalIndex (0 )
140
158
chunk .AddColumn (c1 )
141
159
chunk .AddColumn (c2 )
160
+ chunk .AddColumn (c3 )
142
161
143
- idx , v , isNil := BooleanFirstReduce (chunk , 0 , 0 , 5 )
162
+ idx , v , isNil := BooleanFirstReduce (chunk , chunk . Column ( 0 ). BooleanValues (), 0 , 0 , 5 )
144
163
if ! (idx == 0 && v == true && ! isNil ) {
145
164
t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
146
165
}
147
166
148
- idx , v , isNil = BooleanFirstReduce (chunk , 1 , 0 , 5 )
167
+ idx , v , isNil = BooleanFirstReduce (chunk , chunk . Column ( 1 ). BooleanValues (), 1 , 0 , 5 )
149
168
if ! (idx == 0 && v == false && ! isNil ) {
150
169
t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
151
170
}
171
+
172
+ idx , v , isNil = BooleanFirstReduce (chunk , chunk .Column (2 ).BooleanValues (), 2 , 4 , 5 )
173
+ if ! (idx == 4 && v == false && isNil ) {
174
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
175
+ }
176
+ }
177
+
178
+ func TestIntegerLastReduce (t * testing.T ) {
179
+ chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
180
+ influxql.VarRef {Val : "val_int1" , Type : influxql .Integer },
181
+ influxql.VarRef {Val : "val_int2" , Type : influxql .Integer },
182
+ influxql.VarRef {Val : "val_int3" , Type : influxql .Integer },
183
+ influxql.VarRef {Val : "time" , Type : influxql .Integer },
184
+ ), "test" )
185
+
186
+ c1 := NewColumnImpl (influxql .Integer )
187
+ c1 .AppendNilsV2 (true , true , true , false , false )
188
+ c1 .AppendIntegerValues ([]int64 {1 , 8 , 9 })
189
+
190
+ c2 := NewColumnImpl (influxql .Integer )
191
+ c2 .AppendNilsV2 (true , true , true , true , true )
192
+ c2 .AppendIntegerValues ([]int64 {11 , 18 , 19 , 20 , 21 })
193
+
194
+ c3 := NewColumnImpl (influxql .Integer )
195
+ c3 .AppendNilsV2 (true , true , true , false , false )
196
+ c3 .AppendIntegerValues ([]int64 {11 , 18 , 19 })
197
+
198
+ chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
199
+ chunk .ResetIntervalIndex (0 )
200
+ chunk .AddColumn (c1 )
201
+ chunk .AddColumn (c2 )
202
+ chunk .AddColumn (c3 )
203
+
204
+ // first column
205
+ idx , v , isNil := LastReduce [int64 ](chunk , chunk .Column (0 ).IntegerValues (), 0 , 0 , 5 )
206
+ if ! (idx == 2 && v == 9 && ! isNil ) {
207
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
208
+ }
209
+
210
+ // second column
211
+ idx , v , isNil = LastReduce [int64 ](chunk , chunk .Column (1 ).IntegerValues (), 1 , 0 , 5 )
212
+ if ! (idx == 4 && v == 21 && ! isNil ) {
213
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
214
+ }
215
+
216
+ // third column
217
+ idx , v , isNil = LastReduce [int64 ](chunk , chunk .Column (2 ).IntegerValues (), 2 , 4 , 5 )
218
+ if ! (idx == 4 && v == 0 && isNil ) {
219
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
220
+ }
221
+ }
222
+
223
+ func TestBooleanLastReduce (t * testing.T ) {
224
+ chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
225
+ influxql.VarRef {Val : "val_bool1" , Type : influxql .Boolean },
226
+ influxql.VarRef {Val : "val_bool2" , Type : influxql .Boolean },
227
+ influxql.VarRef {Val : "val_bool3" , Type : influxql .Boolean },
228
+ influxql.VarRef {Val : "time" , Type : influxql .Integer },
229
+ ), "test" )
230
+
231
+ c1 := NewColumnImpl (influxql .Boolean )
232
+ c1 .AppendNilsV2 (true , true , true , false , false )
233
+ c1 .AppendBooleanValues ([]bool {true , false , false })
234
+
235
+ c2 := NewColumnImpl (influxql .Integer )
236
+ c2 .AppendNilsV2 (true , true , true , true , true )
237
+ c2 .AppendBooleanValues ([]bool {false , true , true , true , true })
238
+
239
+ c3 := NewColumnImpl (influxql .Integer )
240
+ c3 .AppendNilsV2 (true , true , true , false , false )
241
+ c3 .AppendBooleanValues ([]bool {false , true , true })
242
+
243
+ chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
244
+ chunk .ResetIntervalIndex (0 )
245
+ chunk .AddColumn (c1 )
246
+ chunk .AddColumn (c2 )
247
+ chunk .AddColumn (c3 )
248
+
249
+ idx , v , isNil := BooleanLastReduce (chunk , chunk .Column (0 ).BooleanValues (), 0 , 0 , 5 )
250
+ if ! (idx == 2 && v == false && ! isNil ) {
251
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
252
+ }
253
+
254
+ idx , v , isNil = BooleanLastReduce (chunk , chunk .Column (1 ).BooleanValues (), 1 , 0 , 5 )
255
+ if ! (idx == 4 && v == true && ! isNil ) {
256
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
257
+ }
258
+
259
+ idx , v , isNil = BooleanLastReduce (chunk , chunk .Column (2 ).BooleanValues (), 2 , 4 , 5 )
260
+ if ! (idx == 4 && v == false && isNil ) {
261
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
262
+ }
263
+ }
264
+
265
+ func TestBooleanMinReduce (t * testing.T ) {
266
+ chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
267
+ influxql.VarRef {Val : "val_bool1" , Type : influxql .Boolean },
268
+ influxql.VarRef {Val : "val_bool2" , Type : influxql .Boolean },
269
+ influxql.VarRef {Val : "time" , Type : influxql .Integer },
270
+ ), "test" )
271
+
272
+ c1 := NewColumnImpl (influxql .Boolean )
273
+ c1 .AppendNilsV2 (true , true , true , false , false )
274
+ c1 .AppendBooleanValues ([]bool {true , false , false })
275
+
276
+ c2 := NewColumnImpl (influxql .Integer )
277
+ c2 .AppendNilsV2 (true , true , true , true , true )
278
+ c2 .AppendBooleanValues ([]bool {false , true , true , true , true })
279
+
280
+ chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
281
+ chunk .ResetIntervalIndex (0 )
282
+ chunk .AddColumn (c1 )
283
+ chunk .AddColumn (c2 )
284
+
285
+ idx , v , isNil := BooleanMinReduce (chunk , chunk .Column (0 ).BooleanValues (), 0 , 0 , 5 )
286
+ if ! (idx == 1 && v == false && ! isNil ) {
287
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
288
+ }
289
+
290
+ idx , v , isNil = BooleanMinReduce (chunk , chunk .Column (1 ).BooleanValues (), 1 , 0 , 5 )
291
+ if ! (idx == 0 && v == false && ! isNil ) {
292
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
293
+ }
294
+ }
295
+
296
+ func TestBooleanMaxReduce (t * testing.T ) {
297
+ chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
298
+ influxql.VarRef {Val : "val_bool1" , Type : influxql .Boolean },
299
+ influxql.VarRef {Val : "val_bool2" , Type : influxql .Boolean },
300
+ influxql.VarRef {Val : "time" , Type : influxql .Integer },
301
+ ), "test" )
302
+
303
+ c1 := NewColumnImpl (influxql .Boolean )
304
+ c1 .AppendNilsV2 (true , true , true , false , false )
305
+ c1 .AppendBooleanValues ([]bool {true , false , false })
306
+
307
+ c2 := NewColumnImpl (influxql .Integer )
308
+ c2 .AppendNilsV2 (true , true , true , true , true )
309
+ c2 .AppendBooleanValues ([]bool {false , true , true , true , true })
310
+
311
+ chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
312
+ chunk .ResetIntervalIndex (0 )
313
+ chunk .AddColumn (c1 )
314
+ chunk .AddColumn (c2 )
315
+
316
+ idx , v , isNil := BooleanMaxReduce (chunk , chunk .Column (0 ).BooleanValues (), 0 , 0 , 5 )
317
+ if ! (idx == 0 && v == true && ! isNil ) {
318
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
319
+ }
320
+
321
+ idx , v , isNil = BooleanMaxReduce (chunk , chunk .Column (1 ).BooleanValues (), 1 , 0 , 5 )
322
+ if ! (idx == 1 && v == true && ! isNil ) {
323
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
324
+ }
325
+ }
326
+
327
+ func TestStringLastMerge (t * testing.T ) {
328
+ prePoint := newStringPoint ()
329
+ prePoint .Set (0 , 1 , "string1" )
330
+
331
+ currentPoint := newStringPoint ()
332
+ currentPoint .Set (1 , 2 , "string2" )
333
+
334
+ StringLastMerge (prePoint , currentPoint )
335
+ if ! (prePoint .time == currentPoint .time &&
336
+ prePoint .index == currentPoint .index &&
337
+ bytes .Compare (prePoint .value , currentPoint .value ) == 0 ) {
338
+ t .Fatal ("prePoint and currentPoint is not equal" )
339
+ }
340
+ }
341
+
342
+ func TestBooleanLastMerge (t * testing.T ) {
343
+ prePoint := newPoint [bool ]()
344
+ prePoint .Set (0 , 1 , true )
345
+
346
+ currentPoint := newPoint [bool ]()
347
+ currentPoint .Set (1 , 2 , false )
348
+
349
+ BooleanLastMerge (prePoint , currentPoint )
350
+ if ! (prePoint .time == currentPoint .time &&
351
+ prePoint .index == currentPoint .index &&
352
+ prePoint .value == currentPoint .value ) {
353
+ t .Fatal ("prePoint and currentPoint is not equal" )
354
+ }
152
355
}
0 commit comments