@@ -353,3 +353,191 @@ func TestBooleanLastMerge(t *testing.T) {
353
353
t .Fatal ("prePoint and currentPoint is not equal" )
354
354
}
355
355
}
356
+
357
+ func TestNumberLastMerge (t * testing.T ) {
358
+ prePoint := newPoint [float64 ]()
359
+ prePoint .Set (0 , 1 , 1.1 )
360
+
361
+ currentPoint := newPoint [float64 ]()
362
+ currentPoint .Set (1 , 2 , 2.2 )
363
+
364
+ LastMerge (prePoint , currentPoint )
365
+ if ! (prePoint .time == currentPoint .time &&
366
+ prePoint .index == currentPoint .index &&
367
+ prePoint .value == currentPoint .value ) {
368
+ t .Fatal ("prePoint and currentPoint is not equal" )
369
+ }
370
+ }
371
+
372
+ func TestStringFirstMerge (t * testing.T ) {
373
+ prePoint := newStringPoint ()
374
+ prePoint .Set (0 , 1 , "string1" )
375
+
376
+ currentPoint := newStringPoint ()
377
+ currentPoint .Set (1 , 0 , "string2" )
378
+
379
+ StringFirstMerge (prePoint , currentPoint )
380
+ if ! (prePoint .time == currentPoint .time &&
381
+ prePoint .index == currentPoint .index &&
382
+ bytes .Compare (prePoint .value , currentPoint .value ) == 0 ) {
383
+ t .Fatal ("prePoint and currentPoint is not equal" )
384
+ }
385
+ }
386
+
387
+ func TestBooleanFirstMerge (t * testing.T ) {
388
+ prePoint := newPoint [bool ]()
389
+ prePoint .Set (0 , 1 , true )
390
+
391
+ currentPoint := newPoint [bool ]()
392
+ currentPoint .Set (1 , 0 , false )
393
+
394
+ BooleanFirstMerge (prePoint , currentPoint )
395
+ if ! (prePoint .time == currentPoint .time &&
396
+ prePoint .index == currentPoint .index &&
397
+ prePoint .value == currentPoint .value ) {
398
+ t .Fatal ("prePoint and currentPoint is not equal" )
399
+ }
400
+ }
401
+
402
+ func TestNumberFirstMerge (t * testing.T ) {
403
+ prePoint := newPoint [float64 ]()
404
+ prePoint .Set (0 , 1 , 1.1 )
405
+
406
+ currentPoint := newPoint [float64 ]()
407
+ currentPoint .Set (1 , 0 , 2.2 )
408
+
409
+ FirstMerge (prePoint , currentPoint )
410
+ if ! (prePoint .time == currentPoint .time &&
411
+ prePoint .index == currentPoint .index &&
412
+ prePoint .value == currentPoint .value ) {
413
+ t .Fatal ("prePoint and currentPoint is not equal" )
414
+ }
415
+ }
416
+
417
+ func TestBooleanFirstTimeColReduce (t * testing.T ) {
418
+ chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
419
+ influxql.VarRef {Val : "val_bool1" , Type : influxql .Boolean },
420
+ influxql.VarRef {Val : "val_bool2" , Type : influxql .Boolean },
421
+ influxql.VarRef {Val : "time" , Type : influxql .Integer },
422
+ ), "test" )
423
+
424
+ c1 := NewColumnImpl (influxql .Boolean )
425
+ c1 .AppendNilsV2 (true , true , true , false , false )
426
+ c1 .AppendBooleanValues ([]bool {true , false , false })
427
+
428
+ c2 := NewColumnImpl (influxql .Boolean )
429
+ c2 .AppendNilsV2 (true , true , true , true , true )
430
+ c2 .AppendBooleanValues ([]bool {false , true , true , true , true })
431
+
432
+ chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
433
+ chunk .ResetIntervalIndex (0 )
434
+ chunk .AddColumn (c1 )
435
+ chunk .AddColumn (c2 )
436
+
437
+ idx , v , isNil := BooleanFirstTimeColReduce (chunk , chunk .Column (0 ).BooleanValues (), 0 , 0 , 5 )
438
+ if ! (idx == 0 && v == true && ! isNil ) {
439
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
440
+ }
441
+
442
+ idx , v , isNil = BooleanFirstTimeColReduce (chunk , chunk .Column (1 ).BooleanValues (), 1 , 0 , 5 )
443
+ if ! (idx == 0 && v == false && ! isNil ) {
444
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
445
+ }
446
+ }
447
+
448
+ func TestFloatFirstTimeColReduce (t * testing.T ) {
449
+ chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
450
+ influxql.VarRef {Val : "val_float1" , Type : influxql .Float },
451
+ influxql.VarRef {Val : "val_float2" , Type : influxql .Float },
452
+ influxql.VarRef {Val : "time" , Type : influxql .Integer },
453
+ ), "test" )
454
+
455
+ c1 := NewColumnImpl (influxql .Float )
456
+ c1 .AppendNilsV2 (true , true , true , false , false )
457
+ c1 .AppendFloatValues ([]float64 {1.1 , 8.2 , 9.3 })
458
+
459
+ c2 := NewColumnImpl (influxql .Float )
460
+ c2 .AppendNilsV2 (true , true , true , true , true )
461
+ c2 .AppendFloatValues ([]float64 {11.1 , 18.2 , 19.3 , 20.4 , 21.5 })
462
+
463
+ chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
464
+ chunk .ResetIntervalIndex (0 )
465
+ chunk .AddColumn (c1 )
466
+ chunk .AddColumn (c2 )
467
+
468
+ // first column
469
+ idx , v , isNil := FirstTimeColReduce [float64 ](chunk , chunk .Column (0 ).FloatValues (), 0 , 0 , 5 )
470
+ if ! (idx == 0 && v == 1.1 && ! isNil ) {
471
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
472
+ }
473
+
474
+ // second column
475
+ idx , v , isNil = FirstTimeColReduce [float64 ](chunk , chunk .Column (1 ).FloatValues (), 1 , 0 , 5 )
476
+ if ! (idx == 0 && v == 11.1 && ! isNil ) {
477
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
478
+ }
479
+ }
480
+
481
+ func TestIntegerLastTimeColReduce (t * testing.T ) {
482
+ chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
483
+ influxql.VarRef {Val : "val_int1" , Type : influxql .Integer },
484
+ influxql.VarRef {Val : "val_int2" , Type : influxql .Integer },
485
+ influxql.VarRef {Val : "time" , Type : influxql .Integer },
486
+ ), "test" )
487
+
488
+ c1 := NewColumnImpl (influxql .Integer )
489
+ c1 .AppendNilsV2 (true , true , true , false , false )
490
+ c1 .AppendIntegerValues ([]int64 {1 , 8 , 9 })
491
+
492
+ c2 := NewColumnImpl (influxql .Integer )
493
+ c2 .AppendNilsV2 (true , true , true , true , true )
494
+ c2 .AppendIntegerValues ([]int64 {11 , 18 , 19 , 20 , 21 })
495
+
496
+ chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
497
+ chunk .ResetIntervalIndex (0 )
498
+ chunk .AddColumn (c1 )
499
+ chunk .AddColumn (c2 )
500
+
501
+ // first column
502
+ idx , v , isNil := LastTimeColReduce [int64 ](chunk , chunk .Column (0 ).IntegerValues (), 0 , 0 , 5 )
503
+ if ! (idx == 2 && v == 9 && ! isNil ) {
504
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
505
+ }
506
+
507
+ // second column
508
+ idx , v , isNil = LastTimeColReduce [int64 ](chunk , chunk .Column (1 ).IntegerValues (), 1 , 0 , 5 )
509
+ if ! (idx == 4 && v == 21 && ! isNil ) {
510
+ t .Fatal ("not expect, idx " , idx , "v " , v , "exist" , isNil )
511
+ }
512
+ }
513
+
514
+ func TestBooleanLastTimeColReduce (t * testing.T ) {
515
+ chunk := NewChunkImpl (hybridqp .NewRowDataTypeImpl (
516
+ influxql.VarRef {Val : "val_bool1" , Type : influxql .Boolean },
517
+ influxql.VarRef {Val : "val_bool2" , Type : influxql .Boolean },
518
+ influxql.VarRef {Val : "time" , Type : influxql .Integer },
519
+ ), "test" )
520
+
521
+ c1 := NewColumnImpl (influxql .Boolean )
522
+ c1 .AppendNilsV2 (true , true , true , false , false )
523
+ c1 .AppendBooleanValues ([]bool {true , false , false })
524
+
525
+ c2 := NewColumnImpl (influxql .Integer )
526
+ c2 .AppendNilsV2 (true , true , true , true , true )
527
+ c2 .AppendBooleanValues ([]bool {false , true , true , true , true })
528
+
529
+ chunk .SetTime ([]int64 {1 , 2 , 3 , 4 , 5 })
530
+ chunk .ResetIntervalIndex (0 )
531
+ chunk .AddColumn (c1 )
532
+ chunk .AddColumn (c2 )
533
+
534
+ idx , v , isNil := BooleanLastTimeColReduce (chunk , chunk .Column (0 ).BooleanValues (), 0 , 0 , 5 )
535
+ if ! (idx == 2 && v == false && ! isNil ) {
536
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
537
+ }
538
+
539
+ idx , v , isNil = BooleanLastTimeColReduce (chunk , chunk .Column (1 ).BooleanValues (), 1 , 0 , 5 )
540
+ if ! (idx == 4 && v == true && ! isNil ) {
541
+ t .Fatal ("not expect, idx " , idx , ", v " , v , ", exist" , isNil )
542
+ }
543
+ }
0 commit comments