@@ -3,6 +3,7 @@ package client_test
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "slices"
6
7
"sort"
7
8
"testing"
8
9
"time"
@@ -887,7 +888,15 @@ func crossJoinQuery(t *testing.T, exec execBatchOrSerial) {
887
888
}
888
889
}
889
890
890
- func TestAsOfJoinQuery (t * testing.T ) {
891
+ func TestAsOfJoinQueryBatched (t * testing.T ) {
892
+ asOfJoinQuery (t , (* client .Client ).ExecBatch )
893
+ }
894
+
895
+ func TestAsOfJoinQuerySerial (t * testing.T ) {
896
+ asOfJoinQuery (t , (* client .Client ).ExecSerial )
897
+ }
898
+
899
+ func asOfJoinQuery (t * testing.T , exec execBatchOrSerial ) {
891
900
ctx := context .Background ()
892
901
893
902
c , err := client .NewClient (ctx , test_tools .GetHost (), test_tools .GetPort (), test_tools .GetAuthType (), test_tools .GetAuthToken ())
@@ -896,53 +905,44 @@ func TestAsOfJoinQuery(t *testing.T) {
896
905
}
897
906
defer c .Close ()
898
907
899
- startTime := time .Now ().Add (time .Duration (- 2 ) * time .Second )
908
+ tempty , err := c .EmptyTable (ctx , 5 )
909
+ test_tools .CheckError (t , "EmptyTable" , err )
910
+ defer tempty .Release (ctx )
900
911
901
- tt1 := c . TimeTableQuery ( 100000 , startTime ).Update ("Col1 = i" )
902
- tt2 := c . TimeTableQuery ( 200000 , startTime ).Update ("Col1 = i" )
912
+ tleft := tempty . Query ( ).Update ("Time = i * 3" , "LValue = 100 + i" )
913
+ tright := tempty . Query ( ).Update ("Time = i * 5" , "RValue = 200 + i" )
903
914
904
- normalTable := tt1 .AsOfJoin (tt2 , []string {"Col1" , "Timestamp " }, nil , client .MatchRuleLessThanEqual )
905
- reverseTable := tt1 .AsOfJoin (tt2 , []string {"Col1" , "Timestamp " }, nil , client .MatchRuleGreaterThanEqual )
915
+ taojLeq := tleft .AsOfJoin (tright , []string {"Time " }, nil , client .MatchRuleLessThanEqual )
916
+ taojGeq := tleft .AsOfJoin (tright , []string {"Time " }, nil , client .MatchRuleGreaterThanEqual )
906
917
907
- tables , err := c .ExecBatch (ctx , tt1 , normalTable , reverseTable )
908
- if err != nil {
909
- t .Errorf ("ExecBatch %s" , err .Error ())
910
- return
911
- }
912
- if len (tables ) != 3 {
918
+ tables , err := exec (c , ctx , taojLeq , taojGeq )
919
+ if len (tables ) != 2 {
913
920
t .Errorf ("wrong number of tables" )
914
- return
915
921
}
916
922
defer tables [0 ].Release (ctx )
917
923
defer tables [1 ].Release (ctx )
918
- defer tables [2 ].Release (ctx )
919
924
920
- ttRec , err := tables [0 ].Snapshot (ctx )
921
- if err != nil {
922
- t .Errorf ("Snapshot %s" , err .Error ())
923
- return
924
- }
925
+ leqRec , err := tables [0 ].Snapshot (ctx )
926
+ test_tools .CheckError (t , "Snapshot" , err )
927
+ defer leqRec .Release ()
925
928
926
- normalRec , err := tables [1 ].Snapshot (ctx )
927
- if err != nil {
928
- t .Errorf ("Snapshot %s" , err .Error ())
929
- return
930
- }
929
+ geqRec , err := tables [1 ].Snapshot (ctx )
930
+ test_tools .CheckError (t , "Snapshot" , err )
931
+ defer geqRec .Release ()
931
932
932
- reverseRec , err := tables [2 ].Snapshot (ctx )
933
- if err != nil {
934
- t .Errorf ("Snapshot %s" , err .Error ())
935
- return
936
- }
933
+ // Column 2 is the RValue column
934
+ actualLeqData := leqRec .Column (2 ).(* array.Int32 ).Int32Values ()
935
+ actualGeqData := geqRec .Column (2 ).(* array.Int32 ).Int32Values ()
937
936
938
- if normalRec .NumRows () == 0 || normalRec .NumRows () > ttRec .NumRows () {
939
- t .Error ("record had wrong size" )
940
- return
937
+ expectedLeqData := []int32 {200 , 200 , 201 , 201 , 202 }
938
+ expectedGeqData := []int32 {200 , 201 , 202 , 202 , 203 }
939
+
940
+ if ! slices .Equal (expectedLeqData , actualLeqData ) {
941
+ t .Errorf ("leq values different expected %v != actual %v" , expectedLeqData , actualLeqData )
941
942
}
942
943
943
- if reverseRec .NumRows () == 0 || reverseRec .NumRows () > ttRec .NumRows () {
944
- t .Error ("record had wrong size" )
945
- return
944
+ if ! slices .Equal (expectedGeqData , actualGeqData ) {
945
+ t .Errorf ("geq values different: expected %v != actual %v" , expectedGeqData , actualGeqData )
946
946
}
947
947
}
948
948
0 commit comments