Skip to content

Commit 88ed1af

Browse files
committed
CASSGO-43: externally-defined type registration
The new RegisterType function 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 native 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 │ new.txt │ │ sec/op │ sec/op vs base │ SingleConn-16 25.92µ ± 1% 25.66µ ± 1% ~ (p=0.123 n=10) ParseRowsFrame-16 1053.5n ± 2% 747.3n ± 3% -29.07% (p=0.000 n=10) Unmarshal_BigInt-16 18.91n ± 0% 20.70n ± 1% +9.49% (p=0.000 n=10) Unmarshal_Blob-16 19.38n ± 0% 21.92n ± 0% +13.08% (p=0.000 n=10) Unmarshal_Boolean-16 16.57n ± 0% 18.80n ± 0% +13.45% (p=0.000 n=10) Unmarshal_Date-16 18.48n ± 0% 20.98n ± 0% +13.53% (p=0.000 n=10) Unmarshal_Decimal-16 196.5n ± 2% 209.1n ± 1% +6.44% (p=0.000 n=10) Unmarshal_Double-16 16.27n ± 1% 18.77n ± 2% +15.37% (p=0.000 n=10) Unmarshal_Duration-16 28.55n ± 0% 29.77n ± 1% +4.26% (p=0.000 n=10) Unmarshal_Float-16 16.65n ± 1% 18.48n ± 1% +10.99% (p=0.000 n=10) Unmarshal_Int-16 19.47n ± 1% 21.95n ± 1% +12.71% (p=0.000 n=10) Unmarshal_Inet-16 30.28n ± 1% 38.32n ± 0% +26.53% (p=0.000 n=10) Unmarshal_SmallInt-16 19.09n ± 0% 21.88n ± 0% +14.67% (p=0.000 n=10) Unmarshal_Time-16 16.57n ± 0% 26.32n ± 1% +58.79% (p=0.000 n=10) Unmarshal_Timestamp-16 16.60n ± 0% 18.43n ± 0% +11.02% (p=0.000 n=10) Unmarshal_TinyInt-16 16.66n ± 0% 21.65n ± 1% +30.02% (p=0.000 n=10) Unmarshal_UUID-16 17.87n ± 0% 19.74n ± 1% +10.46% (p=0.000 n=10) Unmarshal_Varchar-16 18.77n ± 1% 21.93n ± 0% +16.84% (p=0.000 n=10) Unmarshal_List-16 217.1n ± 0% 218.8n ± 2% ~ (p=0.108 n=10) Unmarshal_Set-16 219.5n ± 1% 217.0n ± 0% -1.16% (p=0.000 n=10) Unmarshal_Map-16 392.7n ± 1% 409.2n ± 2% +4.19% (p=0.000 n=10) FramerReadTypeInfo-16 224.7n ± 4% 228.1n ± 1% ~ (p=0.159 n=10) ConnStress-16 9.255µ ± 15% ConnRoutingKey-16 178.4n ± 3% WikiCreateSchema-16 520.9m ± 3% WikiCreatePages-16 1.492m ± 1% WikiSelectAllPages-16 1.959m ± 1% WikiSelectSinglePage-16 1.496m ± 1% WikiSelectPageCount-16 1.658m ± 2% Unmarshal_TupleStrings-16 398.9n ± 2% Unmarshal_TupleInterfaces-16 418.5n ± 1% geomean 502.2n 72.59n +9.98% ¹ ¹ benchmark set differs from baseline; geomeans may not be comparable │ old.txt │ new.txt │ │ B/op │ B/op vs base │ SingleConn-16 3.110Ki ± 0% 3.110Ki ± 0% ~ (p=0.090 n=10) ParseRowsFrame-16 1112.0 ± 0% 856.0 ± 0% -23.02% (p=0.000 n=10) 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 248.0 ± 0% 248.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.670Ki ± 0% ConnRoutingKey-16 32.00 ± 0% WikiCreateSchema-16 53.38Ki ± 1% WikiCreatePages-16 3.866Ki ± 0% WikiSelectAllPages-16 28.74Ki ± 0% WikiSelectSinglePage-16 3.305Ki ± 0% WikiSelectPageCount-16 2.816Ki ± 0% Unmarshal_TupleStrings-16 126.0 ± 0% Unmarshal_TupleInterfaces-16 126.0 ± 0% geomean ² -3.45% ³ ² ¹ all samples are equal ² summaries must be >0 to compute geomean ³ benchmark set differs from baseline; geomeans may not be comparable │ old.txt │ new.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) 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 33.00 ± 0% ConnRoutingKey-16 3.000 ± 0% WikiCreateSchema-16 773.0 ± 1% WikiCreatePages-16 51.00 ± 2% WikiSelectAllPages-16 338.0 ± 0% WikiSelectSinglePage-16 45.00 ± 0% WikiSelectPageCount-16 40.00 ± 0% Unmarshal_TupleStrings-16 8.000 ± 0% Unmarshal_TupleInterfaces-16 8.000 ± 0% geomean ² -2.16% ³ ² ¹ 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 4ad7479 commit 88ed1af

15 files changed

+2692
-1217
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Externally-defined type registration (CASSGO-43)
13+
1214
### Changed
1315

1416
- Don't restrict server authenticator unless PasswordAuthentictor.AllowedAuthenticators is provided (CASSGO-19)
@@ -33,6 +35,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3335

3436
- Standardized spelling of datacenter (CASSGO-35)
3537

38+
- inet columns are now unmarshalled as net.IP when using MapScan or SliceMap (CASSGO-43)
39+
3640
### Fixed
3741
- Cassandra version unmarshal fix (CASSGO-49)
3842

cassandra_test.go

Lines changed: 95 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func TestDurationType(t *testing.T) {
560560
defer session.Close()
561561

562562
if session.cfg.ProtoVersion < 5 {
563-
t.Skip("Duration type is not supported. Please use protocol version >= 4 and cassandra version >= 3.11")
563+
t.Skip("Duration type is not supported. Please use protocol version > 4")
564564
}
565565

566566
if err := createTable(session, `CREATE TABLE gocql_test.duration_table (
@@ -983,7 +983,7 @@ func TestMapScan(t *testing.T) {
983983
}
984984
assertEqual(t, "fullname", "Ada Lovelace", row["fullname"])
985985
assertEqual(t, "age", 30, row["age"])
986-
assertEqual(t, "address", "10.0.0.2", row["address"])
986+
assertDeepEqual(t, "address", net.ParseIP("10.0.0.2").To4(), row["address"])
987987
assertDeepEqual(t, "data", []byte(`{"foo": "bar"}`), row["data"])
988988

989989
// Second iteration using a new map
@@ -993,7 +993,7 @@ func TestMapScan(t *testing.T) {
993993
}
994994
assertEqual(t, "fullname", "Grace Hopper", row["fullname"])
995995
assertEqual(t, "age", 31, row["age"])
996-
assertEqual(t, "address", "10.0.0.1", row["address"])
996+
assertDeepEqual(t, "address", net.ParseIP("10.0.0.1").To4(), row["address"])
997997
assertDeepEqual(t, "data", []byte(nil), row["data"])
998998
}
999999

@@ -1040,7 +1040,7 @@ func TestSliceMap(t *testing.T) {
10401040
m["testset"] = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
10411041
m["testmap"] = map[string]string{"field1": "val1", "field2": "val2", "field3": "val3"}
10421042
m["testvarint"] = bigInt
1043-
m["testinet"] = "213.212.2.19"
1043+
m["testinet"] = net.ParseIP("213.212.2.19").To4()
10441044
sliceMap := []map[string]interface{}{m}
10451045
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
10461046
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 {
@@ -1072,51 +1072,105 @@ func TestSliceMap(t *testing.T) {
10721072
}
10731073
func matchSliceMap(t *testing.T, sliceMap []map[string]interface{}, testMap map[string]interface{}) {
10741074
if sliceMap[0]["testuuid"] != testMap["testuuid"] {
1075-
t.Fatal("returned testuuid did not match")
1075+
t.Fatalf("returned testuuid %#v did not match %#v", sliceMap[0]["testuuid"], testMap["testuuid"])
10761076
}
10771077
if sliceMap[0]["testtimestamp"] != testMap["testtimestamp"] {
1078-
t.Fatal("returned testtimestamp did not match")
1078+
t.Fatalf("returned testtimestamp %#v did not match %#v", sliceMap[0]["testtimestamp"], testMap["testtimestamp"])
10791079
}
10801080
if sliceMap[0]["testvarchar"] != testMap["testvarchar"] {
1081-
t.Fatal("returned testvarchar did not match")
1081+
t.Fatalf("returned testvarchar %#v did not match %#v", sliceMap[0]["testvarchar"], testMap["testvarchar"])
10821082
}
10831083
if sliceMap[0]["testbigint"] != testMap["testbigint"] {
1084-
t.Fatal("returned testbigint did not match")
1084+
t.Fatalf("returned testbigint %#v did not match %#v", sliceMap[0]["testbigint"], testMap["testbigint"])
10851085
}
10861086
if !reflect.DeepEqual(sliceMap[0]["testblob"], testMap["testblob"]) {
1087-
t.Fatal("returned testblob did not match")
1087+
t.Fatalf("returned testblob %#v did not match %#v", sliceMap[0]["testblob"], testMap["testblob"])
10881088
}
10891089
if sliceMap[0]["testbool"] != testMap["testbool"] {
1090-
t.Fatal("returned testbool did not match")
1090+
t.Fatalf("returned testbool %#v did not match %#v", sliceMap[0]["testbool"], testMap["testbool"])
10911091
}
10921092
if sliceMap[0]["testfloat"] != testMap["testfloat"] {
1093-
t.Fatal("returned testfloat did not match")
1093+
t.Fatalf("returned testfloat %#v did not match %#v", sliceMap[0]["testfloat"], testMap["testfloat"])
10941094
}
10951095
if sliceMap[0]["testdouble"] != testMap["testdouble"] {
1096-
t.Fatal("returned testdouble did not match")
1096+
t.Fatalf("returned testdouble %#v did not match %#v", sliceMap[0]["testdouble"], testMap["testdouble"])
10971097
}
1098-
if sliceMap[0]["testinet"] != testMap["testinet"] {
1099-
t.Fatal("returned testinet did not match")
1098+
if !reflect.DeepEqual(sliceMap[0]["testinet"], testMap["testinet"]) {
1099+
t.Fatalf("returned testinet %#v did not match %#v", sliceMap[0]["testinet"], testMap["testinet"])
11001100
}
11011101

11021102
expectedDecimal := sliceMap[0]["testdecimal"].(*inf.Dec)
11031103
returnedDecimal := testMap["testdecimal"].(*inf.Dec)
11041104

11051105
if expectedDecimal.Cmp(returnedDecimal) != 0 {
1106-
t.Fatal("returned testdecimal did not match")
1106+
t.Fatalf("returned testdecimal %#v did not match %#v", sliceMap[0]["testdecimal"], testMap["testdecimal"])
11071107
}
11081108

11091109
if !reflect.DeepEqual(sliceMap[0]["testlist"], testMap["testlist"]) {
1110-
t.Fatal("returned testlist did not match")
1110+
t.Fatalf("returned testlist %#v did not match %#v", sliceMap[0]["testlist"], testMap["testlist"])
11111111
}
11121112
if !reflect.DeepEqual(sliceMap[0]["testset"], testMap["testset"]) {
1113-
t.Fatal("returned testset did not match")
1113+
t.Fatalf("returned testset %#v did not match %#v", sliceMap[0]["testset"], testMap["testset"])
11141114
}
11151115
if !reflect.DeepEqual(sliceMap[0]["testmap"], testMap["testmap"]) {
1116-
t.Fatal("returned testmap did not match")
1116+
t.Fatalf("returned testmap %#v did not match %#v", sliceMap[0]["testmap"], testMap["testmap"])
11171117
}
11181118
if sliceMap[0]["testint"] != testMap["testint"] {
1119-
t.Fatal("returned testint did not match")
1119+
t.Fatalf("returned testint %#v did not match %#v", sliceMap[0]["testint"], testMap["testint"])
1120+
}
1121+
}
1122+
1123+
func TestSliceMap_CopySlices(t *testing.T) {
1124+
session := createSession(t)
1125+
defer session.Close()
1126+
if err := createTable(session, `CREATE TABLE gocql_test.slice_map_copy_table (
1127+
t text,
1128+
u timeuuid,
1129+
l list<text>,
1130+
PRIMARY KEY (t, u)
1131+
)`); err != nil {
1132+
t.Fatal("create table:", err)
1133+
}
1134+
1135+
err := session.Query(
1136+
`INSERT INTO slice_map_copy_table (t, u, l) VALUES ('test', ?, ?)`,
1137+
TimeUUID(), []string{"1", "2"},
1138+
).Exec()
1139+
if err != nil {
1140+
t.Fatal("insert:", err)
1141+
}
1142+
1143+
err = session.Query(
1144+
`INSERT INTO slice_map_copy_table (t, u, l) VALUES ('test', ?, ?)`,
1145+
TimeUUID(), []string{"3", "4"},
1146+
).Exec()
1147+
if err != nil {
1148+
t.Fatal("insert:", err)
1149+
}
1150+
1151+
err = session.Query(
1152+
`INSERT INTO slice_map_copy_table (t, u, l) VALUES ('test', ?, ?)`,
1153+
TimeUUID(), []string{"5", "6"},
1154+
).Exec()
1155+
if err != nil {
1156+
t.Fatal("insert:", err)
1157+
}
1158+
1159+
if returned, retErr := session.Query(`SELECT * FROM slice_map_copy_table WHERE t = 'test'`).Iter().SliceMap(); retErr != nil {
1160+
t.Fatal("select:", retErr)
1161+
} else {
1162+
if len(returned) != 3 {
1163+
t.Fatal("expected 3 rows, got", len(returned))
1164+
}
1165+
if !reflect.DeepEqual(returned[0]["l"], []string{"1", "2"}) {
1166+
t.Fatal("expected [1, 2], got", returned[0]["l"])
1167+
}
1168+
if !reflect.DeepEqual(returned[1]["l"], []string{"3", "4"}) {
1169+
t.Fatal("expected [3, 4], got", returned[1]["l"])
1170+
}
1171+
if !reflect.DeepEqual(returned[2]["l"], []string{"5", "6"}) {
1172+
t.Fatal("expected [5, 6], got", returned[2]["l"])
1173+
}
11201174
}
11211175
}
11221176

@@ -1193,7 +1247,7 @@ func TestSmallInt(t *testing.T) {
11931247
t.Fatal("select:", retErr)
11941248
} else {
11951249
if sliceMap[0]["testsmallint"] != returned[0]["testsmallint"] {
1196-
t.Fatal("returned testsmallint did not match")
1250+
t.Fatalf("returned testsmallint %#v did not match %#v", returned[0]["testsmallint"], sliceMap[0]["testsmallint"])
11971251
}
11981252
}
11991253
}
@@ -1513,9 +1567,7 @@ func injectInvalidPreparedStatement(t *testing.T, session *Session, table string
15131567
Keyspace: "gocql_test",
15141568
Table: table,
15151569
Name: "foo",
1516-
TypeInfo: NativeType{
1517-
typ: TypeVarchar,
1518-
},
1570+
TypeInfo: TypeVarchar,
15191571
},
15201572
},
15211573
},
@@ -2418,15 +2470,13 @@ func TestAggregateMetadata(t *testing.T) {
24182470
expectedAggregrate := AggregateMetadata{
24192471
Keyspace: "gocql_test",
24202472
Name: "average",
2421-
ArgumentTypes: []TypeInfo{NativeType{typ: TypeInt}},
2473+
ArgumentTypes: []TypeInfo{TypeInt},
24222474
InitCond: "(0, 0)",
2423-
ReturnType: NativeType{typ: TypeDouble},
2475+
ReturnType: TypeDouble,
24242476
StateType: TupleTypeInfo{
2425-
NativeType: NativeType{typ: TypeTuple},
2426-
24272477
Elems: []TypeInfo{
2428-
NativeType{typ: TypeInt},
2429-
NativeType{typ: TypeBigInt},
2478+
TypeInt,
2479+
TypeBigInt,
24302480
},
24312481
},
24322482
stateFunc: "avgstate",
@@ -2439,11 +2489,11 @@ func TestAggregateMetadata(t *testing.T) {
24392489
}
24402490

24412491
if !reflect.DeepEqual(aggregates[0], expectedAggregrate) {
2442-
t.Fatalf("aggregate 'average' is %+v, but expected %+v", aggregates[0], expectedAggregrate)
2492+
t.Fatalf("aggregate 'average' is %#v, but expected %#v", aggregates[0], expectedAggregrate)
24432493
}
24442494
expectedAggregrate.Name = "average2"
24452495
if !reflect.DeepEqual(aggregates[1], expectedAggregrate) {
2446-
t.Fatalf("aggregate 'average2' is %+v, but expected %+v", aggregates[1], expectedAggregrate)
2496+
t.Fatalf("aggregate 'average2' is %#v, but expected %#v", aggregates[1], expectedAggregrate)
24472497
}
24482498
}
24492499

@@ -2471,22 +2521,18 @@ func TestFunctionMetadata(t *testing.T) {
24712521
Name: "avgstate",
24722522
ArgumentTypes: []TypeInfo{
24732523
TupleTypeInfo{
2474-
NativeType: NativeType{typ: TypeTuple},
2475-
24762524
Elems: []TypeInfo{
2477-
NativeType{typ: TypeInt},
2478-
NativeType{typ: TypeBigInt},
2525+
TypeInt,
2526+
TypeBigInt,
24792527
},
24802528
},
2481-
NativeType{typ: TypeInt},
2529+
TypeInt,
24822530
},
24832531
ArgumentNames: []string{"state", "val"},
24842532
ReturnType: TupleTypeInfo{
2485-
NativeType: NativeType{typ: TypeTuple},
2486-
24872533
Elems: []TypeInfo{
2488-
NativeType{typ: TypeInt},
2489-
NativeType{typ: TypeBigInt},
2534+
TypeInt,
2535+
TypeBigInt,
24902536
},
24912537
},
24922538
CalledOnNullInput: true,
@@ -2503,22 +2549,20 @@ func TestFunctionMetadata(t *testing.T) {
25032549
Name: "avgfinal",
25042550
ArgumentTypes: []TypeInfo{
25052551
TupleTypeInfo{
2506-
NativeType: NativeType{typ: TypeTuple},
2507-
25082552
Elems: []TypeInfo{
2509-
NativeType{typ: TypeInt},
2510-
NativeType{typ: TypeBigInt},
2553+
TypeInt,
2554+
TypeBigInt,
25112555
},
25122556
},
25132557
},
25142558
ArgumentNames: []string{"state"},
2515-
ReturnType: NativeType{typ: TypeDouble},
2559+
ReturnType: TypeDouble,
25162560
CalledOnNullInput: true,
25172561
Language: "java",
25182562
Body: finalStateBody,
25192563
}
25202564
if !reflect.DeepEqual(avgFinal, expectedAvgFinal) {
2521-
t.Fatalf("function is %+v, but expected %+v", avgFinal, expectedAvgFinal)
2565+
t.Fatalf("function is %#v, but expected %#v", avgFinal, expectedAvgFinal)
25222566
}
25232567
}
25242568

@@ -2621,14 +2665,14 @@ func TestKeyspaceMetadata(t *testing.T) {
26212665
Name: "basicview",
26222666
FieldNames: []string{"birthday", "nationality", "weight", "height"},
26232667
FieldTypes: []TypeInfo{
2624-
NativeType{typ: TypeTimestamp},
2625-
NativeType{typ: textType},
2626-
NativeType{typ: textType},
2627-
NativeType{typ: textType},
2668+
TypeTimestamp,
2669+
textType,
2670+
textType,
2671+
textType,
26282672
},
26292673
}
26302674
if !reflect.DeepEqual(*keyspaceMetadata.UserTypes["basicview"], expectedType) {
2631-
t.Fatalf("type is %+v, but expected %+v", keyspaceMetadata.UserTypes["basicview"], expectedType)
2675+
t.Fatalf("type is %#v, but expected %#v", keyspaceMetadata.UserTypes["basicview"], expectedType)
26322676
}
26332677
if flagCassVersion.Major >= 3 {
26342678
materializedView, found := keyspaceMetadata.MaterializedViews["view_view"]

common_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func createFunctions(t *testing.T, session *Session) {
236236
CALLED ON NULL INPUT
237237
RETURNS double
238238
LANGUAGE java AS
239-
$$double r = 0; if (state.getInt(0) == 0) return null; r = state.getLong(1); r/= state.getInt(0); return Double.valueOf(r);$$
239+
$$double r = 0; if (state.getInt(0) == 0) return null; r = state.getLong(1); r/= state.getInt(0); return Double.valueOf(r);$$
240240
`).Exec(); err != nil {
241241
t.Fatalf("failed to create function with err: %v", err)
242242
}
@@ -280,20 +280,20 @@ func assertTrue(t *testing.T, description string, value bool) {
280280
func assertEqual(t *testing.T, description string, expected, actual interface{}) {
281281
t.Helper()
282282
if expected != actual {
283-
t.Fatalf("expected %s to be (%+v) but was (%+v) instead", description, expected, actual)
283+
t.Fatalf("expected %s to be (%#v) but was (%#v) instead", description, expected, actual)
284284
}
285285
}
286286

287287
func assertDeepEqual(t *testing.T, description string, expected, actual interface{}) {
288288
t.Helper()
289289
if !reflect.DeepEqual(expected, actual) {
290-
t.Fatalf("expected %s to be (%+v) but was (%+v) instead", description, expected, actual)
290+
t.Fatalf("expected %s to be (%#v) but was (%#v) instead", description, expected, actual)
291291
}
292292
}
293293

294294
func assertNil(t *testing.T, description string, actual interface{}) {
295295
t.Helper()
296296
if actual != nil {
297-
t.Fatalf("expected %s to be (nil) but was (%+v) instead", description, actual)
297+
t.Fatalf("expected %s to be (nil) but was (%#v) instead", description, actual)
298298
}
299299
}

0 commit comments

Comments
 (0)