Skip to content

Commit 41fed01

Browse files
Apply review comments
1 parent 57c99b9 commit 41fed01

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

helpers.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -285,35 +285,25 @@ func apacheToCassandraType(t string) string {
285285
// Do not override hex encoded field names
286286
idx := strings.Index(class, ":")
287287
class = class[idx+1:]
288-
act := getApacheCassandraType(class)
289-
val := act.String()
290-
switch act {
291-
case TypeUDT:
292-
i += 2 // skip next two parameters (keyspace and type ID), do not attempt to resolve their type
293-
case TypeCustom:
294-
if isDigitsOnly(class) {
295-
// vector types include dimension (digits) as second type parameter
296-
// getApacheCassandraType() returns "custom" by default, but we need to leave digits intact
297-
val = class
298-
} else {
288+
val := ""
289+
if strings.HasPrefix(class, apacheCassandraTypePrefix) {
290+
act := getApacheCassandraType(class)
291+
val = act.String()
292+
switch act {
293+
case TypeUDT:
294+
i += 2 // skip next two parameters (keyspace and type ID), do not attempt to resolve their type
295+
case TypeCustom:
299296
val = getApacheCassandraCustomSubType(class)
300297
}
298+
} else {
299+
val = class
301300
}
302301
t = strings.Replace(t, class, val, -1)
303302
}
304303
// This is done so it exactly matches what Cassandra returns
305304
return strings.Replace(t, ",", ", ", -1)
306305
}
307306

308-
func isDigitsOnly(s string) bool {
309-
for _, c := range s {
310-
if c < '0' || c > '9' {
311-
return false
312-
}
313-
}
314-
return true
315-
}
316-
317307
func getApacheCassandraType(class string) Type {
318308
switch strings.TrimPrefix(class, apacheCassandraTypePrefix) {
319309
case "AsciiType":

vector_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,23 @@ func TestVector_SubTypeParsing(t *testing.T) {
369369
},
370370
},
371371
},
372+
{
373+
name: "set_map_vector_text_text",
374+
custom: "org.apache.cassandra.db.marshal.SetType(org.apache.cassandra.db.marshal.MapType(org.apache.cassandra.db.marshal.VectorType(org.apache.cassandra.db.marshal.Int32Type, 10),org.apache.cassandra.db.marshal.UTF8Type))",
375+
expected: CollectionType{
376+
NativeType{typ: TypeSet},
377+
nil,
378+
CollectionType{
379+
NativeType{typ: TypeMap},
380+
VectorType{
381+
NativeType{typ: TypeCustom, custom: VECTOR_TYPE},
382+
NativeType{typ: TypeInt},
383+
10,
384+
},
385+
NativeType{typ: TypeVarchar},
386+
},
387+
},
388+
},
372389
}
373390

374391
for _, test := range tests {

0 commit comments

Comments
 (0)