Skip to content

Commit 938b4e1

Browse files
committed
CASSGO-43: externally-defined type registration
The new RegisteredTypes struct can be used to register externally-defined types. You'll need to define your own marshalling and unmarshalling code as well as a TypeInfo implementation. The name and id MUST not collide with existing and future native CQL types. A lot of the type handling was refactored to use the new format for types. Pointers to empty interfaces are accepted by Scan and are used to build the maps in MapScan and SliceMap. inet columns are now unmarshaled as net.IP which is a breaking change. goos: linux goarch: amd64 pkg: github.com/gocql/gocql cpu: AMD EPYC 7B13 │ old.txt │ new2.txt │ │ sec/op │ sec/op vs base │ SingleConn-16 25.87µ ± 2% 25.65µ ± 1% ~ (p=0.280 n=10) ParseRowsFrame-16 870.5n ± 3% 634.6n ± 4% -27.10% (p=0.000 n=10) UnmarshalVarchar-16 47.29n ± 2% UnmarshalUUID-16 3.161n ± 2% Unmarshal_BigInt-16 17.61n ± 9% 17.88n ± 0% ~ (p=0.138 n=10) Unmarshal_Blob-16 19.19n ± 0% 18.69n ± 0% -2.61% (p=0.000 n=10) Unmarshal_Boolean-16 15.71n ± 0% 16.16n ± 1% +2.90% (p=0.000 n=10) Unmarshal_Date-16 18.53n ± 1% 18.64n ± 0% +0.59% (p=0.017 n=10) Unmarshal_Decimal-16 172.2n ± 2% 181.3n ± 1% +5.32% (p=0.000 n=10) Unmarshal_Double-16 16.33n ± 1% 16.20n ± 1% -0.77% (p=0.003 n=10) Unmarshal_Duration-16 26.03n ± 1% 25.05n ± 0% -3.77% (p=0.000 n=10) Unmarshal_Float-16 15.70n ± 0% 15.90n ± 1% +1.31% (p=0.001 n=10) Unmarshal_Int-16 17.80n ± 1% 18.78n ± 2% +5.48% (p=0.000 n=10) Unmarshal_Inet-16 28.68n ± 1% 29.20n ± 1% +1.78% (p=0.001 n=10) Unmarshal_SmallInt-16 17.92n ± 1% 19.37n ± 2% +8.09% (p=0.000 n=10) Unmarshal_Time-16 16.00n ± 1% 16.22n ± 1% +1.37% (p=0.001 n=10) Unmarshal_Timestamp-16 16.00n ± 2% 16.57n ± 2% +3.50% (p=0.000 n=10) Unmarshal_TinyInt-16 16.38n ± 3% 18.41n ± 1% +12.39% (p=0.000 n=10) Unmarshal_UUID-16 16.05n ± 1% 16.34n ± 3% +1.74% (p=0.000 n=10) Unmarshal_Varchar-16 18.86n ± 1% 18.71n ± 1% -0.77% (p=0.003 n=10) Unmarshal_List-16 176.2n ± 4% 183.2n ± 4% +3.97% (p=0.003 n=10) Unmarshal_Set-16 177.7n ± 1% 181.5n ± 0% +2.17% (p=0.000 n=10) Unmarshal_Map-16 374.0n ± 5% 375.2n ± 4% ~ (p=0.218 n=10) FramerReadTypeInfo-16 207.8n ± 3% 214.9n ± 2% +3.44% (p=0.002 n=10) ConnStress-16 14.10µ ± 16% 15.20µ ± 14% ~ (p=0.631 n=10) ConnRoutingKey-16 275.3n ± 4% 197.8n ± 2% -28.17% (p=0.000 n=10) WikiCreateSchema-16 515.9m ± 3% 501.4m ± 3% -2.81% (p=0.011 n=10) WikiCreatePages-16 1.534m ± 1% 1.474m ± 1% -3.90% (p=0.000 n=10) WikiSelectAllPages-16 1.982m ± 3% 1.906m ± 3% -3.84% (p=0.000 n=10) WikiSelectSinglePage-16 1.529m ± 2% 1.479m ± 1% -3.27% (p=0.000 n=10) WikiSelectPageCount-16 1.691m ± 2% 1.646m ± 1% -2.63% (p=0.001 n=10) Unmarshal_TupleStrings-16 329.6n ± 1% Unmarshal_TupleInterfaces-16 357.9n ± 3% geomean 387.3n 475.8n -0.98% ¹ ¹ benchmark set differs from baseline; geomeans may not be comparable │ old.txt │ new2.txt │ │ B/op │ B/op vs base │ SingleConn-16 3.155Ki ± 0% 3.109Ki ± 0% -1.45% (p=0.000 n=10) ParseRowsFrame-16 1128.0 ± 0% 856.0 ± 0% -24.11% (p=0.000 n=10) UnmarshalVarchar-16 32.00 ± 0% UnmarshalUUID-16 0.000 ± 0% Unmarshal_BigInt-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Blob-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Boolean-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Date-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Decimal-16 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Double-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Duration-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Float-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Int-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Inet-16 4.000 ± 0% 4.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_SmallInt-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Time-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Timestamp-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_TinyInt-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_UUID-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Varchar-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_List-16 32.00 ± 0% 32.00 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Set-16 32.00 ± 0% 32.00 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Map-16 280.0 ± 0% 280.0 ± 0% ~ (p=1.000 n=10) ¹ FramerReadTypeInfo-16 160.00 ± 0% 96.00 ± 0% -40.00% (p=0.000 n=10) ConnStress-16 2.956Ki ± 0% 2.669Ki ± 0% -9.70% (p=0.001 n=10) ConnRoutingKey-16 96.00 ± 0% 32.00 ± 0% -66.67% (p=0.000 n=10) WikiCreateSchema-16 59.90Ki ± 3% 51.87Ki ± 4% -13.41% (p=0.000 n=10) WikiCreatePages-16 4.357Ki ± 0% 3.864Ki ± 0% -11.33% (p=0.000 n=10) WikiSelectAllPages-16 38.32Ki ± 0% 28.74Ki ± 0% -25.01% (p=0.000 n=10) WikiSelectSinglePage-16 3.783Ki ± 0% 3.303Ki ± 0% -12.69% (p=0.000 n=10) WikiSelectPageCount-16 3.215Ki ± 0% 2.816Ki ± 0% -12.42% (p=0.000 n=10) Unmarshal_TupleStrings-16 126.0 ± 0% Unmarshal_TupleInterfaces-16 126.0 ± 0% geomean ² -9.27% ³ ² ¹ all samples are equal ² summaries must be >0 to compute geomean ³ benchmark set differs from baseline; geomeans may not be comparable │ old.txt │ new2.txt │ │ allocs/op │ allocs/op vs base │ SingleConn-16 37.00 ± 0% 37.00 ± 0% ~ (p=1.000 n=10) ¹ ParseRowsFrame-16 21.00 ± 0% 13.00 ± 0% -38.10% (p=0.000 n=10) UnmarshalVarchar-16 1.000 ± 0% UnmarshalUUID-16 0.000 ± 0% Unmarshal_BigInt-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Blob-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Boolean-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Date-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Decimal-16 4.000 ± 0% 4.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Double-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Duration-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Float-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Int-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Inet-16 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_SmallInt-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Time-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Timestamp-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_TinyInt-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_UUID-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Varchar-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_List-16 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Set-16 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ Unmarshal_Map-16 5.000 ± 0% 5.000 ± 0% ~ (p=1.000 n=10) ¹ FramerReadTypeInfo-16 4.000 ± 0% 4.000 ± 0% ~ (p=1.000 n=10) ¹ ConnStress-16 35.00 ± 0% 33.00 ± 0% -5.71% (p=0.000 n=10) ConnRoutingKey-16 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) WikiCreateSchema-16 858.0 ± 3% 654.5 ± 4% -23.72% (p=0.000 n=10) WikiCreatePages-16 56.00 ± 2% 51.00 ± 0% -8.93% (p=0.000 n=10) WikiSelectAllPages-16 343.0 ± 0% 338.0 ± 0% -1.46% (p=0.000 n=10) WikiSelectSinglePage-16 50.00 ± 0% 45.00 ± 0% -10.00% (p=0.000 n=10) WikiSelectPageCount-16 45.00 ± 0% 40.00 ± 0% -11.11% (p=0.000 n=10) Unmarshal_TupleStrings-16 8.000 ± 0% Unmarshal_TupleInterfaces-16 8.000 ± 0% geomean ² -4.81% ³ ² ¹ all samples are equal ² summaries must be >0 to compute geomean ³ benchmark set differs from baseline; geomeans may not be comparable Patch by James Hartig for CASSGO-43
1 parent 0551773 commit 938b4e1

22 files changed

+3346
-2099
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Support of sending queries to the specific node with Query.SetHostID() (CASSGO-4)
1717

18-
- Support for Native Protocol 5. Following protocol changes exposed new API
18+
- Support for Native Protocol 5. Following protocol changes exposed new API
1919
Query.SetKeyspace(), Query.WithNowInSeconds(), Batch.SetKeyspace(), Batch.WithNowInSeconds() (CASSGO-1)
2020

21+
- Externally-defined type registration (CASSGO-43)
22+
2123
### Changed
2224

2325
- Move lz4 compressor to lz4 package within the gocql module (CASSGO-32)
@@ -56,6 +58,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5658

5759
- Make `Session` immutable by removing setters and associated mutex (CASSGO-23)
5860

61+
- inet columns are now unmarshalled as net.IP when using MapScan or SliceMap (CASSGO-43)
62+
63+
- NativeType removed (CASSGO-43)
64+
5965
### Fixed
6066
- Cassandra version unmarshal fix (CASSGO-49)
6167

cassandra_test.go

Lines changed: 111 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ func TestDurationType(t *testing.T) {
645645
defer session.Close()
646646

647647
if session.cfg.ProtoVersion < 5 {
648-
t.Skip("Duration type is not supported. Please use protocol version >= 4 and cassandra version >= 3.11")
648+
t.Skip("Duration type is not supported. Please use protocol version > 4")
649649
}
650650

651651
if err := createTable(session, `CREATE TABLE gocql_test.duration_table (
@@ -1068,7 +1068,7 @@ func TestMapScan(t *testing.T) {
10681068
}
10691069
assertEqual(t, "fullname", "Ada Lovelace", row["fullname"])
10701070
assertEqual(t, "age", 30, row["age"])
1071-
assertEqual(t, "address", "10.0.0.2", row["address"])
1071+
assertDeepEqual(t, "address", net.ParseIP("10.0.0.2").To4(), row["address"])
10721072
assertDeepEqual(t, "data", []byte(`{"foo": "bar"}`), row["data"])
10731073

10741074
// Second iteration using a new map
@@ -1078,7 +1078,7 @@ func TestMapScan(t *testing.T) {
10781078
}
10791079
assertEqual(t, "fullname", "Grace Hopper", row["fullname"])
10801080
assertEqual(t, "age", 31, row["age"])
1081-
assertEqual(t, "address", "10.0.0.1", row["address"])
1081+
assertDeepEqual(t, "address", net.ParseIP("10.0.0.1").To4(), row["address"])
10821082
assertDeepEqual(t, "data", []byte(nil), row["data"])
10831083
}
10841084

@@ -1125,7 +1125,7 @@ func TestSliceMap(t *testing.T) {
11251125
m["testset"] = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
11261126
m["testmap"] = map[string]string{"field1": "val1", "field2": "val2", "field3": "val3"}
11271127
m["testvarint"] = bigInt
1128-
m["testinet"] = "213.212.2.19"
1128+
m["testinet"] = net.ParseIP("213.212.2.19").To4()
11291129
sliceMap := []map[string]interface{}{m}
11301130
if err := session.Query(`INSERT INTO slice_map_table (testuuid, testtimestamp, testvarchar, testbigint, testblob, testbool, testfloat, testdouble, testint, testdecimal, testlist, testset, testmap, testvarint, testinet) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
11311131
m["testuuid"], m["testtimestamp"], m["testvarchar"], m["testbigint"], m["testblob"], m["testbool"], m["testfloat"], m["testdouble"], m["testint"], m["testdecimal"], m["testlist"], m["testset"], m["testmap"], m["testvarint"], m["testinet"]).Exec(); err != nil {
@@ -1157,51 +1157,105 @@ func TestSliceMap(t *testing.T) {
11571157
}
11581158
func matchSliceMap(t *testing.T, sliceMap []map[string]interface{}, testMap map[string]interface{}) {
11591159
if sliceMap[0]["testuuid"] != testMap["testuuid"] {
1160-
t.Fatal("returned testuuid did not match")
1160+
t.Fatalf("returned testuuid %#v did not match %#v", sliceMap[0]["testuuid"], testMap["testuuid"])
11611161
}
11621162
if sliceMap[0]["testtimestamp"] != testMap["testtimestamp"] {
1163-
t.Fatal("returned testtimestamp did not match")
1163+
t.Fatalf("returned testtimestamp %#v did not match %#v", sliceMap[0]["testtimestamp"], testMap["testtimestamp"])
11641164
}
11651165
if sliceMap[0]["testvarchar"] != testMap["testvarchar"] {
1166-
t.Fatal("returned testvarchar did not match")
1166+
t.Fatalf("returned testvarchar %#v did not match %#v", sliceMap[0]["testvarchar"], testMap["testvarchar"])
11671167
}
11681168
if sliceMap[0]["testbigint"] != testMap["testbigint"] {
1169-
t.Fatal("returned testbigint did not match")
1169+
t.Fatalf("returned testbigint %#v did not match %#v", sliceMap[0]["testbigint"], testMap["testbigint"])
11701170
}
11711171
if !reflect.DeepEqual(sliceMap[0]["testblob"], testMap["testblob"]) {
1172-
t.Fatal("returned testblob did not match")
1172+
t.Fatalf("returned testblob %#v did not match %#v", sliceMap[0]["testblob"], testMap["testblob"])
11731173
}
11741174
if sliceMap[0]["testbool"] != testMap["testbool"] {
1175-
t.Fatal("returned testbool did not match")
1175+
t.Fatalf("returned testbool %#v did not match %#v", sliceMap[0]["testbool"], testMap["testbool"])
11761176
}
11771177
if sliceMap[0]["testfloat"] != testMap["testfloat"] {
1178-
t.Fatal("returned testfloat did not match")
1178+
t.Fatalf("returned testfloat %#v did not match %#v", sliceMap[0]["testfloat"], testMap["testfloat"])
11791179
}
11801180
if sliceMap[0]["testdouble"] != testMap["testdouble"] {
1181-
t.Fatal("returned testdouble did not match")
1181+
t.Fatalf("returned testdouble %#v did not match %#v", sliceMap[0]["testdouble"], testMap["testdouble"])
11821182
}
1183-
if sliceMap[0]["testinet"] != testMap["testinet"] {
1184-
t.Fatal("returned testinet did not match")
1183+
if !reflect.DeepEqual(sliceMap[0]["testinet"], testMap["testinet"]) {
1184+
t.Fatalf("returned testinet %#v did not match %#v", sliceMap[0]["testinet"], testMap["testinet"])
11851185
}
11861186

11871187
expectedDecimal := sliceMap[0]["testdecimal"].(*inf.Dec)
11881188
returnedDecimal := testMap["testdecimal"].(*inf.Dec)
11891189

11901190
if expectedDecimal.Cmp(returnedDecimal) != 0 {
1191-
t.Fatal("returned testdecimal did not match")
1191+
t.Fatalf("returned testdecimal %#v did not match %#v", sliceMap[0]["testdecimal"], testMap["testdecimal"])
11921192
}
11931193

11941194
if !reflect.DeepEqual(sliceMap[0]["testlist"], testMap["testlist"]) {
1195-
t.Fatal("returned testlist did not match")
1195+
t.Fatalf("returned testlist %#v did not match %#v", sliceMap[0]["testlist"], testMap["testlist"])
11961196
}
11971197
if !reflect.DeepEqual(sliceMap[0]["testset"], testMap["testset"]) {
1198-
t.Fatal("returned testset did not match")
1198+
t.Fatalf("returned testset %#v did not match %#v", sliceMap[0]["testset"], testMap["testset"])
11991199
}
12001200
if !reflect.DeepEqual(sliceMap[0]["testmap"], testMap["testmap"]) {
1201-
t.Fatal("returned testmap did not match")
1201+
t.Fatalf("returned testmap %#v did not match %#v", sliceMap[0]["testmap"], testMap["testmap"])
12021202
}
12031203
if sliceMap[0]["testint"] != testMap["testint"] {
1204-
t.Fatal("returned testint did not match")
1204+
t.Fatalf("returned testint %#v did not match %#v", sliceMap[0]["testint"], testMap["testint"])
1205+
}
1206+
}
1207+
1208+
func TestSliceMap_CopySlices(t *testing.T) {
1209+
session := createSession(t)
1210+
defer session.Close()
1211+
if err := createTable(session, `CREATE TABLE gocql_test.slice_map_copy_table (
1212+
t text,
1213+
u timeuuid,
1214+
l list<text>,
1215+
PRIMARY KEY (t, u)
1216+
)`); err != nil {
1217+
t.Fatal("create table:", err)
1218+
}
1219+
1220+
err := session.Query(
1221+
`INSERT INTO slice_map_copy_table (t, u, l) VALUES ('test', ?, ?)`,
1222+
TimeUUID(), []string{"1", "2"},
1223+
).Exec()
1224+
if err != nil {
1225+
t.Fatal("insert:", err)
1226+
}
1227+
1228+
err = session.Query(
1229+
`INSERT INTO slice_map_copy_table (t, u, l) VALUES ('test', ?, ?)`,
1230+
TimeUUID(), []string{"3", "4"},
1231+
).Exec()
1232+
if err != nil {
1233+
t.Fatal("insert:", err)
1234+
}
1235+
1236+
err = session.Query(
1237+
`INSERT INTO slice_map_copy_table (t, u, l) VALUES ('test', ?, ?)`,
1238+
TimeUUID(), []string{"5", "6"},
1239+
).Exec()
1240+
if err != nil {
1241+
t.Fatal("insert:", err)
1242+
}
1243+
1244+
if returned, retErr := session.Query(`SELECT * FROM slice_map_copy_table WHERE t = 'test'`).Iter().SliceMap(); retErr != nil {
1245+
t.Fatal("select:", retErr)
1246+
} else {
1247+
if len(returned) != 3 {
1248+
t.Fatal("expected 3 rows, got", len(returned))
1249+
}
1250+
if !reflect.DeepEqual(returned[0]["l"], []string{"1", "2"}) {
1251+
t.Fatal("expected [1, 2], got", returned[0]["l"])
1252+
}
1253+
if !reflect.DeepEqual(returned[1]["l"], []string{"3", "4"}) {
1254+
t.Fatal("expected [3, 4], got", returned[1]["l"])
1255+
}
1256+
if !reflect.DeepEqual(returned[2]["l"], []string{"5", "6"}) {
1257+
t.Fatal("expected [5, 6], got", returned[2]["l"])
1258+
}
12051259
}
12061260
}
12071261

@@ -1278,7 +1332,7 @@ func TestSmallInt(t *testing.T) {
12781332
t.Fatal("select:", retErr)
12791333
} else {
12801334
if sliceMap[0]["testsmallint"] != returned[0]["testsmallint"] {
1281-
t.Fatal("returned testsmallint did not match")
1335+
t.Fatalf("returned testsmallint %#v did not match %#v", returned[0]["testsmallint"], sliceMap[0]["testsmallint"])
12821336
}
12831337
}
12841338
}
@@ -1598,7 +1652,7 @@ func injectInvalidPreparedStatement(t *testing.T, session *Session, table string
15981652
Keyspace: "gocql_test",
15991653
Table: table,
16001654
Name: "foo",
1601-
TypeInfo: NativeType{
1655+
TypeInfo: varcharLikeCQLType{
16021656
typ: TypeVarchar,
16031657
},
16041658
},
@@ -2515,19 +2569,18 @@ func TestAggregateMetadata(t *testing.T) {
25152569
t.Fatal("expected two aggregates")
25162570
}
25172571

2518-
protoVer := byte(session.cfg.ProtoVersion)
25192572
expectedAggregrate := AggregateMetadata{
25202573
Keyspace: "gocql_test",
25212574
Name: "average",
2522-
ArgumentTypes: []TypeInfo{NativeType{typ: TypeInt, proto: protoVer}},
2575+
ArgumentTypes: []TypeInfo{intCQLType{}},
25232576
InitCond: "(0, 0)",
2524-
ReturnType: NativeType{typ: TypeDouble, proto: protoVer},
2577+
ReturnType: doubleCQLType{},
25252578
StateType: TupleTypeInfo{
2526-
NativeType: NativeType{typ: TypeTuple, proto: protoVer},
2527-
25282579
Elems: []TypeInfo{
2529-
NativeType{typ: TypeInt, proto: protoVer},
2530-
NativeType{typ: TypeBigInt, proto: protoVer},
2580+
intCQLType{},
2581+
bigIntLikeCQLType{
2582+
typ: TypeBigInt,
2583+
},
25312584
},
25322585
},
25332586
stateFunc: "avgstate",
@@ -2540,11 +2593,11 @@ func TestAggregateMetadata(t *testing.T) {
25402593
}
25412594

25422595
if !reflect.DeepEqual(aggregates[0], expectedAggregrate) {
2543-
t.Fatalf("aggregate 'average' is %+v, but expected %+v", aggregates[0], expectedAggregrate)
2596+
t.Fatalf("aggregate 'average' is %#v, but expected %#v", aggregates[0], expectedAggregrate)
25442597
}
25452598
expectedAggregrate.Name = "average2"
25462599
if !reflect.DeepEqual(aggregates[1], expectedAggregrate) {
2547-
t.Fatalf("aggregate 'average2' is %+v, but expected %+v", aggregates[1], expectedAggregrate)
2600+
t.Fatalf("aggregate 'average2' is %#v, but expected %#v", aggregates[1], expectedAggregrate)
25482601
}
25492602
}
25502603

@@ -2566,29 +2619,28 @@ func TestFunctionMetadata(t *testing.T) {
25662619
avgState := functions[1]
25672620
avgFinal := functions[0]
25682621

2569-
protoVer := byte(session.cfg.ProtoVersion)
25702622
avgStateBody := "if (val !=null) {state.setInt(0, state.getInt(0)+1); state.setLong(1, state.getLong(1)+val.intValue());}return state;"
25712623
expectedAvgState := FunctionMetadata{
25722624
Keyspace: "gocql_test",
25732625
Name: "avgstate",
25742626
ArgumentTypes: []TypeInfo{
25752627
TupleTypeInfo{
2576-
NativeType: NativeType{typ: TypeTuple, proto: protoVer},
2577-
25782628
Elems: []TypeInfo{
2579-
NativeType{typ: TypeInt, proto: protoVer},
2580-
NativeType{typ: TypeBigInt, proto: protoVer},
2629+
intCQLType{},
2630+
bigIntLikeCQLType{
2631+
typ: TypeBigInt,
2632+
},
25812633
},
25822634
},
2583-
NativeType{typ: TypeInt, proto: protoVer},
2635+
intCQLType{},
25842636
},
25852637
ArgumentNames: []string{"state", "val"},
25862638
ReturnType: TupleTypeInfo{
2587-
NativeType: NativeType{typ: TypeTuple, proto: protoVer},
2588-
25892639
Elems: []TypeInfo{
2590-
NativeType{typ: TypeInt, proto: protoVer},
2591-
NativeType{typ: TypeBigInt, proto: protoVer},
2640+
intCQLType{},
2641+
bigIntLikeCQLType{
2642+
typ: TypeBigInt,
2643+
},
25922644
},
25932645
},
25942646
CalledOnNullInput: true,
@@ -2605,22 +2657,22 @@ func TestFunctionMetadata(t *testing.T) {
26052657
Name: "avgfinal",
26062658
ArgumentTypes: []TypeInfo{
26072659
TupleTypeInfo{
2608-
NativeType: NativeType{typ: TypeTuple, proto: protoVer},
2609-
26102660
Elems: []TypeInfo{
2611-
NativeType{typ: TypeInt, proto: protoVer},
2612-
NativeType{typ: TypeBigInt, proto: protoVer},
2661+
intCQLType{},
2662+
bigIntLikeCQLType{
2663+
typ: TypeBigInt,
2664+
},
26132665
},
26142666
},
26152667
},
26162668
ArgumentNames: []string{"state"},
2617-
ReturnType: NativeType{typ: TypeDouble, proto: protoVer},
2669+
ReturnType: doubleCQLType{},
26182670
CalledOnNullInput: true,
26192671
Language: "java",
26202672
Body: finalStateBody,
26212673
}
26222674
if !reflect.DeepEqual(avgFinal, expectedAvgFinal) {
2623-
t.Fatalf("function is %+v, but expected %+v", avgFinal, expectedAvgFinal)
2675+
t.Fatalf("function is %#v, but expected %#v", avgFinal, expectedAvgFinal)
26242676
}
26252677
}
26262678

@@ -2718,20 +2770,25 @@ func TestKeyspaceMetadata(t *testing.T) {
27182770
if flagCassVersion.Before(3, 0, 0) {
27192771
textType = TypeVarchar
27202772
}
2721-
protoVer := byte(session.cfg.ProtoVersion)
27222773
expectedType := UserTypeMetadata{
27232774
Keyspace: "gocql_test",
27242775
Name: "basicview",
27252776
FieldNames: []string{"birthday", "nationality", "weight", "height"},
27262777
FieldTypes: []TypeInfo{
2727-
NativeType{typ: TypeTimestamp, proto: protoVer},
2728-
NativeType{typ: textType, proto: protoVer},
2729-
NativeType{typ: textType, proto: protoVer},
2730-
NativeType{typ: textType, proto: protoVer},
2778+
timestampCQLType{},
2779+
varcharLikeCQLType{
2780+
typ: textType,
2781+
},
2782+
varcharLikeCQLType{
2783+
typ: textType,
2784+
},
2785+
varcharLikeCQLType{
2786+
typ: textType,
2787+
},
27312788
},
27322789
}
27332790
if !reflect.DeepEqual(*keyspaceMetadata.UserTypes["basicview"], expectedType) {
2734-
t.Fatalf("type is %+v, but expected %+v", keyspaceMetadata.UserTypes["basicview"], expectedType)
2791+
t.Fatalf("type is %#v, but expected %#v", keyspaceMetadata.UserTypes["basicview"], expectedType)
27352792
}
27362793
if flagCassVersion.Major >= 3 {
27372794
materializedView, found := keyspaceMetadata.MaterializedViews["view_view"]
@@ -3542,9 +3599,9 @@ func TestQuery_SetKeyspace(t *testing.T) {
35423599
}
35433600

35443601
const keyspaceStmt = `
3545-
CREATE KEYSPACE IF NOT EXISTS gocql_query_keyspace_override_test
3602+
CREATE KEYSPACE IF NOT EXISTS gocql_query_keyspace_override_test
35463603
WITH replication = {
3547-
'class': 'SimpleStrategy',
3604+
'class': 'SimpleStrategy',
35483605
'replication_factor': '1'
35493606
};
35503607
`

cluster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ type ClusterConfig struct {
274274
// default: 0.25.
275275
NextPagePrefetch float64
276276

277+
// RegisteredTypes will be copied for all sessions created from this Cluster.
278+
// If not provided, a copy of GlobalTypes will be used.
279+
RegisteredTypes *RegisteredTypes
280+
277281
// internal config for testing
278282
disableControlConn bool
279283
}

common_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func createFunctions(t *testing.T, session *Session) {
245245
CALLED ON NULL INPUT
246246
RETURNS double
247247
LANGUAGE java AS
248-
$$double r = 0; if (state.getInt(0) == 0) return null; r = state.getLong(1); r/= state.getInt(0); return Double.valueOf(r);$$
248+
$$double r = 0; if (state.getInt(0) == 0) return null; r = state.getLong(1); r/= state.getInt(0); return Double.valueOf(r);$$
249249
`).Exec(); err != nil {
250250
t.Fatalf("failed to create function with err: %v", err)
251251
}
@@ -297,20 +297,20 @@ func randomText(size int) string {
297297
func assertEqual(t *testing.T, description string, expected, actual interface{}) {
298298
t.Helper()
299299
if expected != actual {
300-
t.Fatalf("expected %s to be (%+v) but was (%+v) instead", description, expected, actual)
300+
t.Fatalf("expected %s to be (%#v) but was (%#v) instead", description, expected, actual)
301301
}
302302
}
303303

304304
func assertDeepEqual(t *testing.T, description string, expected, actual interface{}) {
305305
t.Helper()
306306
if !reflect.DeepEqual(expected, actual) {
307-
t.Fatalf("expected %s to be (%+v) but was (%+v) instead", description, expected, actual)
307+
t.Fatalf("expected %s to be (%#v) but was (%#v) instead", description, expected, actual)
308308
}
309309
}
310310

311311
func assertNil(t *testing.T, description string, actual interface{}) {
312312
t.Helper()
313313
if actual != nil {
314-
t.Fatalf("expected %s to be (nil) but was (%+v) instead", description, actual)
314+
t.Fatalf("expected %s to be (nil) but was (%#v) instead", description, actual)
315315
}
316316
}

0 commit comments

Comments
 (0)