Skip to content

Commit a4d8a5b

Browse files
Support vector of tuples
1 parent 907e69e commit a4d8a5b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

marshal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ func isVectorVariableLengthType(elemType TypeInfo) bool {
18271827
return true
18281828
case TypeInet:
18291829
return true
1830-
case TypeList, TypeSet, TypeMap, TypeUDT:
1830+
case TypeList, TypeSet, TypeMap, TypeUDT, TypeTuple:
18311831
return true
18321832
case TypeCustom:
18331833
switch elemType.(type) {

metadata.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ const (
12111211
SET_TYPE = "org.apache.cassandra.db.marshal.SetType"
12121212
MAP_TYPE = "org.apache.cassandra.db.marshal.MapType"
12131213
UDT_TYPE = "org.apache.cassandra.db.marshal.UserType"
1214+
TUPLE_TYPE = "org.apache.cassandra.db.marshal.TupleType"
12141215
VECTOR_TYPE = "org.apache.cassandra.db.marshal.VectorType"
12151216
)
12161217

@@ -1386,6 +1387,19 @@ func (class *typeParserClassNode) asTypeInfo() TypeInfo {
13861387
Elements: fields,
13871388
}
13881389
}
1390+
if strings.HasPrefix(class.name, TUPLE_TYPE) {
1391+
fields := make([]TypeInfo, len(class.params))
1392+
for i := 0; i < len(class.params); i++ {
1393+
fields[i] = class.params[i].class.asTypeInfo()
1394+
}
1395+
return TupleTypeInfo{
1396+
NativeType: NativeType{
1397+
typ: TypeTuple,
1398+
proto: class.proto,
1399+
},
1400+
Elems: fields,
1401+
}
1402+
}
13891403
if strings.HasPrefix(class.name, VECTOR_TYPE) {
13901404
dim, _ := strconv.Atoi(class.params[1].class.name)
13911405
return VectorType{

vector_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func TestVector_Types(t *testing.T) {
170170
{{2, 3}, {2, -1}, {3}, {0}, {-1.3}},
171171
{{1, 1000.0}, {0}, {}, {12, 14, 15, 16}, {-1.3}},
172172
}},
173+
{name: "vector_tuple_text_int_float", cqlType: "tuple<text, int, float>", value: [][]interface{}{{"a", 1, float32(0.5)}, {"b", 2, float32(-1.2)}, {"c", 3, float32(0)}}},
174+
{name: "vector_tuple_text_list_text", cqlType: "tuple<text, list<text>>", value: [][]interface{}{{"a", []string{"b", "c"}}, {"d", []string{"e", "f", "g"}}, {"h", []string{"i"}}}},
173175
{name: "vector_set_text", cqlType: "set<text>", value: [][]string{{"a", "b"}, {"c", "d"}, {"e", "f"}}},
174176
{name: "vector_list_int", cqlType: "list<int>", value: [][]int32{{1, 2, 3}, {-1, -2, -3}, {0, 0, 0}}},
175177
{name: "vector_map_text_int", cqlType: "map<text, int>", value: []map[string]int{map1, map2, map3}},
@@ -329,6 +331,18 @@ func TestVector_SubTypeParsing(t *testing.T) {
329331
},
330332
},
331333
},
334+
{
335+
name: "tuple",
336+
custom: "org.apache.cassandra.db.marshal.TupleType(org.apache.cassandra.db.marshal.UTF8Type,org.apache.cassandra.db.marshal.Int32Type,org.apache.cassandra.db.marshal.UTF8Type)",
337+
expected: TupleTypeInfo{
338+
NativeType{typ: TypeTuple},
339+
[]TypeInfo{
340+
NativeType{typ: TypeVarchar},
341+
NativeType{typ: TypeInt},
342+
NativeType{typ: TypeVarchar},
343+
},
344+
},
345+
},
332346
{
333347
name: "vector_vector_inet",
334348
custom: "org.apache.cassandra.db.marshal.VectorType(org.apache.cassandra.db.marshal.VectorType(org.apache.cassandra.db.marshal.InetAddressType, 2), 3)",

0 commit comments

Comments
 (0)