Skip to content

Commit 7d8664a

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. 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 │ new3.txt │ │ sec/op │ sec/op vs base │ SingleConn-16 25.87µ ± 2% 26.49µ ± 1% +2.40% (p=0.000 n=10) ParseRowsFrame-16 870.5n ± 3% 683.1n ± 4% -21.52% (p=0.000 n=10) UnmarshalVarchar-16 47.29n ± 2% UnmarshalUUID-16 3.161n ± 2% Unmarshal_BigInt-16 17.61n ± 9% 13.47n ± 0% -23.48% (p=0.000 n=10) Unmarshal_Blob-16 19.19n ± 0% 14.79n ± 2% -22.88% (p=0.000 n=10) Unmarshal_Boolean-16 15.71n ± 0% 12.20n ± 1% -22.32% (p=0.000 n=10) Unmarshal_Date-16 18.53n ± 1% 15.98n ± 0% -13.73% (p=0.000 n=10) Unmarshal_Decimal-16 172.15n ± 2% 96.55n ± 1% -43.92% (p=0.000 n=10) Unmarshal_Double-16 16.33n ± 1% 12.21n ± 0% -25.20% (p=0.000 n=10) Unmarshal_Duration-16 26.03n ± 1% 22.30n ± 1% -14.33% (p=0.000 n=10) Unmarshal_Float-16 15.70n ± 0% 12.21n ± 0% -22.17% (p=0.000 n=10) Unmarshal_Int-16 17.80n ± 1% 14.43n ± 0% -18.96% (p=0.000 n=10) Unmarshal_Inet-16 28.68n ± 1% 25.25n ± 1% -11.96% (p=0.000 n=10) Unmarshal_SmallInt-16 17.92n ± 1% 14.45n ± 1% -19.37% (p=0.000 n=10) Unmarshal_Time-16 16.00n ± 1% 12.25n ± 3% -23.47% (p=0.000 n=10) Unmarshal_Timestamp-16 16.00n ± 2% 12.23n ± 0% -23.62% (p=0.000 n=10) Unmarshal_TinyInt-16 16.38n ± 3% 14.40n ± 1% -12.09% (p=0.000 n=10) Unmarshal_UUID-16 16.05n ± 1% 12.56n ± 1% -21.77% (p=0.000 n=10) Unmarshal_Varchar-16 18.86n ± 1% 14.81n ± 1% -21.43% (p=0.000 n=10) Unmarshal_List-16 176.2n ± 4% 172.9n ± 1% -1.90% (p=0.002 n=10) Unmarshal_Set-16 177.7n ± 1% 172.9n ± 0% -2.67% (p=0.000 n=10) Unmarshal_Map-16 374.0n ± 5% 348.0n ± 2% -6.94% (p=0.000 n=10) Unmarshal_TupleStrings-16 387.9n ± 1% 206.1n ± 1% -46.85% (p=0.000 n=10) Unmarshal_TupleInterfaces-16 485.4n ± 2% 289.6n ± 3% -40.34% (p=0.000 n=10) FramerReadTypeInfo-16 207.8n ± 3% 168.6n ± 5% -18.89% (p=0.000 n=10) ConnStress-16 14.10µ ± 16% 16.05µ ± 19% ~ (p=0.363 n=10) ConnRoutingKey-16 275.3n ± 4% 276.9n ± 2% ~ (p=0.869 n=10) WikiCreateSchema-16 515.9m ± 3% 484.9m ± 3% -6.02% (p=0.000 n=10) WikiCreatePages-16 1.534m ± 1% 1.469m ± 1% -4.21% (p=0.000 n=10) WikiSelectAllPages-16 1.982m ± 3% 1.900m ± 1% -4.13% (p=0.000 n=10) WikiSelectSinglePage-16 1.529m ± 2% 1.472m ± 0% -3.72% (p=0.000 n=10) WikiSelectPageCount-16 1.691m ± 2% 1.629m ± 2% -3.67% (p=0.000 n=10) FramerReadCol-16 107.7n ± 3% 124.6n ± 1% +15.79% (p=0.000 n=10) geomean 375.5n 391.1n -15.90% ¹ ¹ benchmark set differs from baseline; geomeans may not be comparable │ old.txt │ new3.txt │ │ B/op │ B/op vs base │ SingleConn-16 3.155Ki ± 0% 3.157Ki ± 0% +0.06% (p=0.000 n=10) ParseRowsFrame-16 1128.0 ± 0% 872.0 ± 0% -22.70% (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% 48.00 ± 0% -50.00% (p=0.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) ¹ Unmarshal_TupleStrings-16 158.00 ± 0% 62.00 ± 0% -60.76% (p=0.000 n=10) Unmarshal_TupleInterfaces-16 190.00 ± 0% 94.00 ± 0% -50.53% (p=0.000 n=10) FramerReadTypeInfo-16 160.00 ± 0% 96.00 ± 0% -40.00% (p=0.000 n=10) ConnStress-16 2.956Ki ± 0% 2.958Ki ± 0% ~ (p=0.238 n=10) ConnRoutingKey-16 96.00 ± 0% 96.00 ± 0% ~ (p=1.000 n=10) ¹ WikiCreateSchema-16 59.90Ki ± 3% 57.90Ki ± 1% -3.34% (p=0.004 n=10) WikiCreatePages-16 4.357Ki ± 0% 4.355Ki ± 0% ~ (p=0.236 n=10) WikiSelectAllPages-16 38.32Ki ± 0% 38.32Ki ± 0% ~ (p=0.322 n=10) WikiSelectSinglePage-16 3.783Ki ± 0% 3.781Ki ± 0% ~ (p=0.239 n=10) WikiSelectPageCount-16 3.215Ki ± 0% 3.212Ki ± 0% ~ (p=0.232 n=10) FramerReadCol-16 99.00 ± 0% 67.00 ± 0% -32.32% (p=0.000 n=10) geomean ² -10.43% ³ ² ¹ all samples are equal ² summaries must be >0 to compute geomean ³ benchmark set differs from baseline; geomeans may not be comparable │ old.txt │ new3.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% 3.000 ± 0% -25.00% (p=0.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) ¹ Unmarshal_TupleStrings-16 8.000 ± 0% 4.000 ± 0% -50.00% (p=0.000 n=10) Unmarshal_TupleInterfaces-16 10.000 ± 0% 6.000 ± 0% -40.00% (p=0.000 n=10) FramerReadTypeInfo-16 4.000 ± 0% 4.000 ± 0% ~ (p=1.000 n=10) ¹ ConnStress-16 35.00 ± 0% 35.00 ± 0% ~ (p=1.000 n=10) ConnRoutingKey-16 4.000 ± 0% 4.000 ± 0% ~ (p=1.000 n=10) ¹ WikiCreateSchema-16 858.0 ± 3% 746.0 ± 1% -13.05% (p=0.000 n=10) WikiCreatePages-16 56.00 ± 2% 56.00 ± 2% ~ (p=1.000 n=10) WikiSelectAllPages-16 343.0 ± 0% 343.0 ± 0% ~ (p=1.000 n=10) ¹ WikiSelectSinglePage-16 50.00 ± 0% 50.00 ± 0% ~ (p=1.000 n=10) ¹ WikiSelectPageCount-16 45.00 ± 0% 45.00 ± 0% ~ (p=1.000 n=10) ¹ FramerReadCol-16 3.000 ± 0% 3.000 ± 0% ~ (p=1.000 n=10) ¹ geomean ² -6.38% ³ ² ¹ 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; reviewed by João Reis for CASSGO-43
1 parent 90bcc9c commit 7d8664a

24 files changed

+4515
-2499
lines changed

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Support vector type (CASSGO-11)
1717
- Allow SERIAL and LOCAL_SERIAL on SELECT statements (CASSGO-26)
1818
- Support of sending queries to the specific node with Query.SetHostID() (CASSGO-4)
19-
- Support for Native Protocol 5 (CASSGO-1)
19+
- Support for Native Protocol 5. Following protocol changes exposed new API
20+
Query.SetKeyspace(), Query.WithNowInSeconds(), Batch.SetKeyspace(), Batch.WithNowInSeconds() (CASSGO-1)
21+
- Externally-defined type registration (CASSGO-43)
2022

2123
### Changed
2224

@@ -36,12 +38,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3638
- Refactor HostInfo creation and ConnectAddress() method (CASSGO-45)
3739
- gocql.Compressor interface changes to follow append-like design. Bumped Go version to 1.19 (CASSGO-1)
3840
- Refactoring hostpool package test and Expose HostInfo creation (CASSGO-59)
39-
4041
- Move "execute batch" methods to Batch type (CASSGO-57)
41-
4242
- Make `Session` immutable by removing setters and associated mutex (CASSGO-23)
43+
- inet columns default to net.IP when using MapScan or SliceMap (CASSGO-43)
44+
- NativeType removed (CASSGO-43)
45+
- `New` and `NewWithError` removed and replaced with `Zero` (CASSGO-43)
4346

4447
### Fixed
48+
4549
- Cassandra version unmarshal fix (CASSGO-49)
4650
- Retry policy now takes into account query idempotency (CASSGO-27)
4751
- Don't return error to caller with RetryType Ignore (CASSGO-28)
@@ -50,7 +54,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5054
- Skip metadata only if the prepared result includes metadata (CASSGO-40)
5155
- Don't panic in MapExecuteBatchCAS if no `[applied]` column is returned (CASSGO-42)
5256
- Fix deadlock in refresh debouncer stop (CASSGO-41)
53-
5457
- Endless query execution fix (CASSGO-50)
5558

5659
## [1.7.0] - 2024-09-23

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: varcharLikeTypeInfo{
16021656
typ: TypeVarchar,
16031657
},
16041658
},
@@ -2497,19 +2551,18 @@ func TestAggregateMetadata(t *testing.T) {
24972551
t.Fatal("expected two aggregates")
24982552
}
24992553

2500-
protoVer := byte(session.cfg.ProtoVersion)
25012554
expectedAggregrate := AggregateMetadata{
25022555
Keyspace: "gocql_test",
25032556
Name: "average",
2504-
ArgumentTypes: []TypeInfo{NativeType{typ: TypeInt, proto: protoVer}},
2557+
ArgumentTypes: []TypeInfo{intTypeInfo{}},
25052558
InitCond: "(0, 0)",
2506-
ReturnType: NativeType{typ: TypeDouble, proto: protoVer},
2559+
ReturnType: doubleTypeInfo{},
25072560
StateType: TupleTypeInfo{
2508-
NativeType: NativeType{typ: TypeTuple, proto: protoVer},
2509-
25102561
Elems: []TypeInfo{
2511-
NativeType{typ: TypeInt, proto: protoVer},
2512-
NativeType{typ: TypeBigInt, proto: protoVer},
2562+
intTypeInfo{},
2563+
bigIntLikeTypeInfo{
2564+
typ: TypeBigInt,
2565+
},
25132566
},
25142567
},
25152568
stateFunc: "avgstate",
@@ -2522,11 +2575,11 @@ func TestAggregateMetadata(t *testing.T) {
25222575
}
25232576

25242577
if !reflect.DeepEqual(aggregates[0], expectedAggregrate) {
2525-
t.Fatalf("aggregate 'average' is %+v, but expected %+v", aggregates[0], expectedAggregrate)
2578+
t.Fatalf("aggregate 'average' is %#v, but expected %#v", aggregates[0], expectedAggregrate)
25262579
}
25272580
expectedAggregrate.Name = "average2"
25282581
if !reflect.DeepEqual(aggregates[1], expectedAggregrate) {
2529-
t.Fatalf("aggregate 'average2' is %+v, but expected %+v", aggregates[1], expectedAggregrate)
2582+
t.Fatalf("aggregate 'average2' is %#v, but expected %#v", aggregates[1], expectedAggregrate)
25302583
}
25312584
}
25322585

@@ -2548,29 +2601,28 @@ func TestFunctionMetadata(t *testing.T) {
25482601
avgState := functions[1]
25492602
avgFinal := functions[0]
25502603

2551-
protoVer := byte(session.cfg.ProtoVersion)
25522604
avgStateBody := "if (val !=null) {state.setInt(0, state.getInt(0)+1); state.setLong(1, state.getLong(1)+val.intValue());}return state;"
25532605
expectedAvgState := FunctionMetadata{
25542606
Keyspace: "gocql_test",
25552607
Name: "avgstate",
25562608
ArgumentTypes: []TypeInfo{
25572609
TupleTypeInfo{
2558-
NativeType: NativeType{typ: TypeTuple, proto: protoVer},
2559-
25602610
Elems: []TypeInfo{
2561-
NativeType{typ: TypeInt, proto: protoVer},
2562-
NativeType{typ: TypeBigInt, proto: protoVer},
2611+
intTypeInfo{},
2612+
bigIntLikeTypeInfo{
2613+
typ: TypeBigInt,
2614+
},
25632615
},
25642616
},
2565-
NativeType{typ: TypeInt, proto: protoVer},
2617+
intTypeInfo{},
25662618
},
25672619
ArgumentNames: []string{"state", "val"},
25682620
ReturnType: TupleTypeInfo{
2569-
NativeType: NativeType{typ: TypeTuple, proto: protoVer},
2570-
25712621
Elems: []TypeInfo{
2572-
NativeType{typ: TypeInt, proto: protoVer},
2573-
NativeType{typ: TypeBigInt, proto: protoVer},
2622+
intTypeInfo{},
2623+
bigIntLikeTypeInfo{
2624+
typ: TypeBigInt,
2625+
},
25742626
},
25752627
},
25762628
CalledOnNullInput: true,
@@ -2587,22 +2639,22 @@ func TestFunctionMetadata(t *testing.T) {
25872639
Name: "avgfinal",
25882640
ArgumentTypes: []TypeInfo{
25892641
TupleTypeInfo{
2590-
NativeType: NativeType{typ: TypeTuple, proto: protoVer},
2591-
25922642
Elems: []TypeInfo{
2593-
NativeType{typ: TypeInt, proto: protoVer},
2594-
NativeType{typ: TypeBigInt, proto: protoVer},
2643+
intTypeInfo{},
2644+
bigIntLikeTypeInfo{
2645+
typ: TypeBigInt,
2646+
},
25952647
},
25962648
},
25972649
},
25982650
ArgumentNames: []string{"state"},
2599-
ReturnType: NativeType{typ: TypeDouble, proto: protoVer},
2651+
ReturnType: doubleTypeInfo{},
26002652
CalledOnNullInput: true,
26012653
Language: "java",
26022654
Body: finalStateBody,
26032655
}
26042656
if !reflect.DeepEqual(avgFinal, expectedAvgFinal) {
2605-
t.Fatalf("function is %+v, but expected %+v", avgFinal, expectedAvgFinal)
2657+
t.Fatalf("function is %#v, but expected %#v", avgFinal, expectedAvgFinal)
26062658
}
26072659
}
26082660

@@ -2700,20 +2752,25 @@ func TestKeyspaceMetadata(t *testing.T) {
27002752
if flagCassVersion.Before(3, 0, 0) {
27012753
textType = TypeVarchar
27022754
}
2703-
protoVer := byte(session.cfg.ProtoVersion)
27042755
expectedType := UserTypeMetadata{
27052756
Keyspace: "gocql_test",
27062757
Name: "basicview",
27072758
FieldNames: []string{"birthday", "nationality", "weight", "height"},
27082759
FieldTypes: []TypeInfo{
2709-
NativeType{typ: TypeTimestamp, proto: protoVer},
2710-
NativeType{typ: textType, proto: protoVer},
2711-
NativeType{typ: textType, proto: protoVer},
2712-
NativeType{typ: textType, proto: protoVer},
2760+
timestampTypeInfo{},
2761+
varcharLikeTypeInfo{
2762+
typ: textType,
2763+
},
2764+
varcharLikeTypeInfo{
2765+
typ: textType,
2766+
},
2767+
varcharLikeTypeInfo{
2768+
typ: textType,
2769+
},
27132770
},
27142771
}
27152772
if !reflect.DeepEqual(*keyspaceMetadata.UserTypes["basicview"], expectedType) {
2716-
t.Fatalf("type is %+v, but expected %+v", keyspaceMetadata.UserTypes["basicview"], expectedType)
2773+
t.Fatalf("type is %#v, but expected %#v", keyspaceMetadata.UserTypes["basicview"], expectedType)
27172774
}
27182775
if flagCassVersion.Major >= 3 {
27192776
materializedView, found := keyspaceMetadata.MaterializedViews["view_view"]
@@ -3520,9 +3577,9 @@ func TestQuery_SetKeyspace(t *testing.T) {
35203577
}
35213578

35223579
const keyspaceStmt = `
3523-
CREATE KEYSPACE IF NOT EXISTS gocql_query_keyspace_override_test
3580+
CREATE KEYSPACE IF NOT EXISTS gocql_query_keyspace_override_test
35243581
WITH replication = {
3525-
'class': 'SimpleStrategy',
3582+
'class': 'SimpleStrategy',
35263583
'replication_factor': '1'
35273584
};
35283585
`

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
}

0 commit comments

Comments
 (0)