@@ -560,7 +560,7 @@ func TestDurationType(t *testing.T) {
560
560
defer session .Close ()
561
561
562
562
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 " )
564
564
}
565
565
566
566
if err := createTable (session , `CREATE TABLE gocql_test.duration_table (
@@ -983,7 +983,7 @@ func TestMapScan(t *testing.T) {
983
983
}
984
984
assertEqual (t , "fullname" , "Ada Lovelace" , row ["fullname" ])
985
985
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" ])
987
987
assertDeepEqual (t , "data" , []byte (`{"foo": "bar"}` ), row ["data" ])
988
988
989
989
// Second iteration using a new map
@@ -993,7 +993,7 @@ func TestMapScan(t *testing.T) {
993
993
}
994
994
assertEqual (t , "fullname" , "Grace Hopper" , row ["fullname" ])
995
995
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" ])
997
997
assertDeepEqual (t , "data" , []byte (nil ), row ["data" ])
998
998
}
999
999
@@ -1040,7 +1040,7 @@ func TestSliceMap(t *testing.T) {
1040
1040
m ["testset" ] = []int {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 }
1041
1041
m ["testmap" ] = map [string ]string {"field1" : "val1" , "field2" : "val2" , "field3" : "val3" }
1042
1042
m ["testvarint" ] = bigInt
1043
- m ["testinet" ] = "213.212.2.19"
1043
+ m ["testinet" ] = net . ParseIP ( "213.212.2.19" ). To4 ()
1044
1044
sliceMap := []map [string ]interface {}{m }
1045
1045
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` ,
1046
1046
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) {
1072
1072
}
1073
1073
func matchSliceMap (t * testing.T , sliceMap []map [string ]interface {}, testMap map [string ]interface {}) {
1074
1074
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" ] )
1076
1076
}
1077
1077
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" ] )
1079
1079
}
1080
1080
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" ] )
1082
1082
}
1083
1083
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" ] )
1085
1085
}
1086
1086
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" ] )
1088
1088
}
1089
1089
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" ] )
1091
1091
}
1092
1092
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" ] )
1094
1094
}
1095
1095
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" ] )
1097
1097
}
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" ] )
1100
1100
}
1101
1101
1102
1102
expectedDecimal := sliceMap [0 ]["testdecimal" ].(* inf.Dec )
1103
1103
returnedDecimal := testMap ["testdecimal" ].(* inf.Dec )
1104
1104
1105
1105
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" ] )
1107
1107
}
1108
1108
1109
1109
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" ] )
1111
1111
}
1112
1112
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" ] )
1114
1114
}
1115
1115
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" ] )
1117
1117
}
1118
1118
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
+ }
1120
1174
}
1121
1175
}
1122
1176
@@ -1193,7 +1247,7 @@ func TestSmallInt(t *testing.T) {
1193
1247
t .Fatal ("select:" , retErr )
1194
1248
} else {
1195
1249
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" ] )
1197
1251
}
1198
1252
}
1199
1253
}
@@ -2415,18 +2469,19 @@ func TestAggregateMetadata(t *testing.T) {
2415
2469
t .Fatal ("expected two aggregates" )
2416
2470
}
2417
2471
2472
+ protoVer := byte (session .cfg .ProtoVersion )
2418
2473
expectedAggregrate := AggregateMetadata {
2419
2474
Keyspace : "gocql_test" ,
2420
2475
Name : "average" ,
2421
- ArgumentTypes : []TypeInfo {NativeType {typ : TypeInt }},
2476
+ ArgumentTypes : []TypeInfo {NativeType {proto : protoVer , typ : TypeInt }},
2422
2477
InitCond : "(0, 0)" ,
2423
- ReturnType : NativeType {typ : TypeDouble },
2478
+ ReturnType : NativeType {proto : protoVer , typ : TypeDouble },
2424
2479
StateType : TupleTypeInfo {
2425
- NativeType : NativeType {typ : TypeTuple },
2480
+ NativeType : NativeType {proto : protoVer , typ : TypeTuple },
2426
2481
2427
2482
Elems : []TypeInfo {
2428
- NativeType {typ : TypeInt },
2429
- NativeType {typ : TypeBigInt },
2483
+ NativeType {proto : protoVer , typ : TypeInt },
2484
+ NativeType {proto : protoVer , typ : TypeBigInt },
2430
2485
},
2431
2486
},
2432
2487
stateFunc : "avgstate" ,
@@ -2439,11 +2494,11 @@ func TestAggregateMetadata(t *testing.T) {
2439
2494
}
2440
2495
2441
2496
if ! reflect .DeepEqual (aggregates [0 ], expectedAggregrate ) {
2442
- t .Fatalf ("aggregate 'average' is %+ v, but expected %+ v" , aggregates [0 ], expectedAggregrate )
2497
+ t .Fatalf ("aggregate 'average' is %# v, but expected %# v" , aggregates [0 ], expectedAggregrate )
2443
2498
}
2444
2499
expectedAggregrate .Name = "average2"
2445
2500
if ! reflect .DeepEqual (aggregates [1 ], expectedAggregrate ) {
2446
- t .Fatalf ("aggregate 'average2' is %+ v, but expected %+ v" , aggregates [1 ], expectedAggregrate )
2501
+ t .Fatalf ("aggregate 'average2' is %# v, but expected %# v" , aggregates [1 ], expectedAggregrate )
2447
2502
}
2448
2503
}
2449
2504
@@ -2465,28 +2520,29 @@ func TestFunctionMetadata(t *testing.T) {
2465
2520
avgState := functions [1 ]
2466
2521
avgFinal := functions [0 ]
2467
2522
2523
+ protoVer := byte (session .cfg .ProtoVersion )
2468
2524
avgStateBody := "if (val !=null) {state.setInt(0, state.getInt(0)+1); state.setLong(1, state.getLong(1)+val.intValue());}return state;"
2469
2525
expectedAvgState := FunctionMetadata {
2470
2526
Keyspace : "gocql_test" ,
2471
2527
Name : "avgstate" ,
2472
2528
ArgumentTypes : []TypeInfo {
2473
2529
TupleTypeInfo {
2474
- NativeType : NativeType {typ : TypeTuple },
2530
+ NativeType : NativeType {proto : protoVer , typ : TypeTuple },
2475
2531
2476
2532
Elems : []TypeInfo {
2477
- NativeType {typ : TypeInt },
2478
- NativeType {typ : TypeBigInt },
2533
+ NativeType {proto : protoVer , typ : TypeInt },
2534
+ NativeType {proto : protoVer , typ : TypeBigInt },
2479
2535
},
2480
2536
},
2481
- NativeType {typ : TypeInt },
2537
+ NativeType {proto : protoVer , typ : TypeInt },
2482
2538
},
2483
2539
ArgumentNames : []string {"state" , "val" },
2484
2540
ReturnType : TupleTypeInfo {
2485
- NativeType : NativeType {typ : TypeTuple },
2541
+ NativeType : NativeType {proto : protoVer , typ : TypeTuple },
2486
2542
2487
2543
Elems : []TypeInfo {
2488
- NativeType {typ : TypeInt },
2489
- NativeType {typ : TypeBigInt },
2544
+ NativeType {proto : protoVer , typ : TypeInt },
2545
+ NativeType {proto : protoVer , typ : TypeBigInt },
2490
2546
},
2491
2547
},
2492
2548
CalledOnNullInput : true ,
@@ -2503,22 +2559,22 @@ func TestFunctionMetadata(t *testing.T) {
2503
2559
Name : "avgfinal" ,
2504
2560
ArgumentTypes : []TypeInfo {
2505
2561
TupleTypeInfo {
2506
- NativeType : NativeType {typ : TypeTuple },
2562
+ NativeType : NativeType {proto : protoVer , typ : TypeTuple },
2507
2563
2508
2564
Elems : []TypeInfo {
2509
- NativeType {typ : TypeInt },
2510
- NativeType {typ : TypeBigInt },
2565
+ NativeType {proto : protoVer , typ : TypeInt },
2566
+ NativeType {proto : protoVer , typ : TypeBigInt },
2511
2567
},
2512
2568
},
2513
2569
},
2514
2570
ArgumentNames : []string {"state" },
2515
- ReturnType : NativeType {typ : TypeDouble },
2571
+ ReturnType : NativeType {proto : protoVer , typ : TypeDouble },
2516
2572
CalledOnNullInput : true ,
2517
2573
Language : "java" ,
2518
2574
Body : finalStateBody ,
2519
2575
}
2520
2576
if ! reflect .DeepEqual (avgFinal , expectedAvgFinal ) {
2521
- t .Fatalf ("function is %+ v, but expected %+ v" , avgFinal , expectedAvgFinal )
2577
+ t .Fatalf ("function is %# v, but expected %# v" , avgFinal , expectedAvgFinal )
2522
2578
}
2523
2579
}
2524
2580
@@ -2616,19 +2672,20 @@ func TestKeyspaceMetadata(t *testing.T) {
2616
2672
if flagCassVersion .Before (3 , 0 , 0 ) {
2617
2673
textType = TypeVarchar
2618
2674
}
2675
+ protoVer := byte (session .cfg .ProtoVersion )
2619
2676
expectedType := UserTypeMetadata {
2620
2677
Keyspace : "gocql_test" ,
2621
2678
Name : "basicview" ,
2622
2679
FieldNames : []string {"birthday" , "nationality" , "weight" , "height" },
2623
2680
FieldTypes : []TypeInfo {
2624
- NativeType {typ : TypeTimestamp },
2625
- NativeType {typ : textType },
2626
- NativeType {typ : textType },
2627
- NativeType {typ : textType },
2681
+ NativeType {proto : protoVer , typ : TypeTimestamp },
2682
+ NativeType {proto : protoVer , typ : textType },
2683
+ NativeType {proto : protoVer , typ : textType },
2684
+ NativeType {proto : protoVer , typ : textType },
2628
2685
},
2629
2686
}
2630
2687
if ! reflect .DeepEqual (* keyspaceMetadata .UserTypes ["basicview" ], expectedType ) {
2631
- t .Fatalf ("type is %+ v, but expected %+ v" , keyspaceMetadata .UserTypes ["basicview" ], expectedType )
2688
+ t .Fatalf ("type is %# v, but expected %# v" , keyspaceMetadata .UserTypes ["basicview" ], expectedType )
2632
2689
}
2633
2690
if flagCassVersion .Major >= 3 {
2634
2691
materializedView , found := keyspaceMetadata .MaterializedViews ["view_view" ]
0 commit comments