Skip to content

Commit 68f9350

Browse files
authored
Go Client: Rewrite TestAsOfJoinQuery in query_test.go (deephaven#5059)
1 parent d3dae15 commit 68f9350

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

go/pkg/client/query_test.go

+35-35
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client_test
33
import (
44
"context"
55
"errors"
6+
"slices"
67
"sort"
78
"testing"
89
"time"
@@ -887,7 +888,15 @@ func crossJoinQuery(t *testing.T, exec execBatchOrSerial) {
887888
}
888889
}
889890

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) {
891900
ctx := context.Background()
892901

893902
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) {
896905
}
897906
defer c.Close()
898907

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)
900911

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")
903914

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)
906917

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 {
913920
t.Errorf("wrong number of tables")
914-
return
915921
}
916922
defer tables[0].Release(ctx)
917923
defer tables[1].Release(ctx)
918-
defer tables[2].Release(ctx)
919924

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()
925928

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()
931932

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()
937936

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)
941942
}
942943

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)
946946
}
947947
}
948948

0 commit comments

Comments
 (0)