lukasz-antoniak commented on code in PR #1828:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1828#discussion_r2035056118


##########
helpers.go:
##########
@@ -162,54 +164,154 @@ func getCassandraBaseType(name string) Type {
        }
 }
 
-func getCassandraType(name string, logger StdLogger) TypeInfo {
+// Parses long Java-style type definition to internal data structures.
+func getCassandraLongType(name string, protoVer byte, logger StdLogger) 
TypeInfo {
+       if strings.HasPrefix(name, SET_TYPE) {
+               return CollectionType{
+                       NativeType: NewNativeType(protoVer, TypeSet),
+                       Elem:       
getCassandraLongType(strings.TrimPrefix(name[:len(name)-1], SET_TYPE+"("), 
protoVer, logger),
+               }
+       } else if strings.HasPrefix(name, LIST_TYPE) {
+               return CollectionType{
+                       NativeType: NewNativeType(protoVer, TypeList),
+                       Elem:       
getCassandraLongType(strings.TrimPrefix(name[:len(name)-1], LIST_TYPE+"("), 
protoVer, logger),
+               }
+       } else if strings.HasPrefix(name, MAP_TYPE) {
+               names := 
splitJavaCompositeTypes(strings.TrimPrefix(name[:len(name)-1], MAP_TYPE+"("))
+               if len(names) != 2 {
+                       logger.Printf("gocql: error parsing map type, it has %d 
subelements, expecting 2\n", len(names))
+                       return NewNativeType(protoVer, TypeCustom)
+               }
+               return CollectionType{
+                       NativeType: NewNativeType(protoVer, TypeMap),
+                       Key:        getCassandraLongType(names[0], protoVer, 
logger),
+                       Elem:       getCassandraLongType(names[1], protoVer, 
logger),
+               }
+       } else if strings.HasPrefix(name, TUPLE_TYPE) {
+               names := 
splitJavaCompositeTypes(strings.TrimPrefix(name[:len(name)-1], TUPLE_TYPE+"("))
+               types := make([]TypeInfo, len(names))
+
+               for i, name := range names {
+                       types[i] = getCassandraLongType(name, protoVer, logger)
+               }
+
+               return TupleTypeInfo{
+                       NativeType: NewNativeType(protoVer, TypeTuple),
+                       Elems:      types,
+               }
+       } else if strings.HasPrefix(name, UDT_TYPE) {
+               names := 
splitJavaCompositeTypes(strings.TrimPrefix(name[:len(name)-1], UDT_TYPE+"("))
+               fields := make([]UDTField, len(names)-2)
+
+               for i := 2; i < len(names); i++ {
+                       spec := strings.Split(names[i], ":")
+                       fieldName, _ := hex.DecodeString(spec[0])
+                       fields[i-2] = UDTField{
+                               Name: string(fieldName),
+                               Type: getCassandraLongType(spec[1], protoVer, 
logger),
+                       }
+               }
+
+               udtName, _ := hex.DecodeString(names[1])
+               return UDTTypeInfo{
+                       NativeType: NewNativeType(protoVer, TypeUDT),
+                       KeySpace:   names[0],
+                       Name:       string(udtName),
+                       Elements:   fields,
+               }
+       } else if strings.HasPrefix(name, VECTOR_TYPE) {
+               names := 
splitJavaCompositeTypes(strings.TrimPrefix(name[:len(name)-1], VECTOR_TYPE+"("))

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to