Skip to content

Commit ae2d2e4

Browse files
Apply review comments
1 parent 24daa93 commit ae2d2e4

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

helpers.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func getCassandraBaseType(name string) Type {
164164
}
165165
}
166166

167-
// Parse long Java-style type definition to internal data structures.
167+
// Parses long Java-style type definition to internal data structures.
168168
func getCassandraLongType(name string, protoVer byte, logger StdLogger) TypeInfo {
169169
if strings.HasPrefix(name, SET_TYPE) {
170170
return CollectionType{
@@ -179,7 +179,7 @@ func getCassandraLongType(name string, protoVer byte, logger StdLogger) TypeInfo
179179
} else if strings.HasPrefix(name, MAP_TYPE) {
180180
names := splitJavaCompositeTypes(strings.TrimPrefix(name[:len(name)-1], MAP_TYPE+"("))
181181
if len(names) != 2 {
182-
logger.Printf("Error parsing map type, it has %d subelements, expecting 2\n", len(names))
182+
logger.Printf("gocql: error parsing map type, it has %d subelements, expecting 2\n", len(names))
183183
return NewNativeType(protoVer, TypeCustom)
184184
}
185185
return CollectionType{
@@ -208,7 +208,7 @@ func getCassandraLongType(name string, protoVer byte, logger StdLogger) TypeInfo
208208
fieldName, _ := hex.DecodeString(spec[0])
209209
fields[i-2] = UDTField{
210210
Name: string(fieldName),
211-
Type: getTypeInfo(spec[1], protoVer, logger),
211+
Type: getCassandraLongType(spec[1], protoVer, logger),
212212
}
213213
}
214214

@@ -222,7 +222,11 @@ func getCassandraLongType(name string, protoVer byte, logger StdLogger) TypeInfo
222222
} else if strings.HasPrefix(name, VECTOR_TYPE) {
223223
names := splitJavaCompositeTypes(strings.TrimPrefix(name[:len(name)-1], VECTOR_TYPE+"("))
224224
subType := getCassandraLongType(strings.TrimSpace(names[0]), protoVer, logger)
225-
dim, _ := strconv.Atoi(strings.TrimSpace(names[1]))
225+
dim, err := strconv.Atoi(strings.TrimSpace(names[1]))
226+
if err != nil {
227+
logger.Printf("gocql: error parsing vector dimensions: %v\n", err)
228+
return NewNativeType(protoVer, TypeCustom)
229+
}
226230

227231
return VectorType{
228232
NativeType: NewCustomType(protoVer, TypeCustom, VECTOR_TYPE),
@@ -238,9 +242,7 @@ func getCassandraLongType(name string, protoVer byte, logger StdLogger) TypeInfo
238242
}
239243
}
240244

241-
// Parses short CQL type representation to internal data structures.
242-
// Mapping of long Java-style type definition into short format is performed in
243-
// apacheToCassandraType function.
245+
// Parses short CQL type representation (e.g. map<text, text>) to internal data structures.
244246
func getCassandraType(name string, protoVer byte, logger StdLogger) TypeInfo {
245247
if strings.HasPrefix(name, "frozen<") {
246248
return getCassandraType(strings.TrimPrefix(name[:len(name)-1], "frozen<"), protoVer, logger)
@@ -335,21 +337,6 @@ func splitCompositeTypes(name string, typeOpen int32, typeClose int32) []string
335337
return parts
336338
}
337339

338-
// Convert long Java style type definition into the short CQL type names.
339-
func apacheToCassandraType(t string) string {
340-
t = strings.Replace(t, apacheCassandraTypePrefix, "", -1)
341-
t = strings.Replace(t, "(", "<", -1)
342-
t = strings.Replace(t, ")", ">", -1)
343-
types := strings.FieldsFunc(t, func(r rune) bool {
344-
return r == '<' || r == '>' || r == ','
345-
})
346-
for _, typ := range types {
347-
t = strings.Replace(t, typ, getApacheCassandraType(typ).String(), -1)
348-
}
349-
// This is done so it exactly matches what Cassandra returns
350-
return strings.Replace(t, ",", ", ", -1)
351-
}
352-
353340
func getApacheCassandraType(class string) Type {
354341
switch strings.TrimPrefix(class, apacheCassandraTypePrefix) {
355342
case "AsciiType":

metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ func getColumnMetadata(session *Session, keyspaceName string) ([]ColumnMetadata,
949949

950950
func getTypeInfo(t string, protoVer byte, logger StdLogger) TypeInfo {
951951
if strings.HasPrefix(t, apacheCassandraTypePrefix) {
952-
t = apacheToCassandraType(t)
952+
return getCassandraLongType(t, protoVer, logger)
953953
}
954954
return getCassandraType(t, protoVer, logger)
955955
}

0 commit comments

Comments
 (0)