joao-r-reis commented on code in PR #1828:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1828#discussion_r1819394660


##########
metadata.go:
##########
@@ -1291,6 +1297,26 @@ func (t *typeParser) parse() typeParserResult {
                        reversed:    reversed,
                        collections: collections,
                }
+       } else if strings.HasPrefix(ast.name, VECTOR_TYPE) {
+               count := len(ast.params)
+
+               types := make([]TypeInfo, count)
+               reversed := make([]bool, count)
+
+               for i, param := range ast.params[:count] {
+                       class := param.class
+                       reversed[i] = strings.HasPrefix(class.name, 
REVERSED_TYPE)
+                       if reversed[i] {
+                               class = class.params[0].class
+                       }
+                       types[i] = class.asTypeInfo()
+               }
+
+               return typeParserResult{
+                       isComposite: true,
+                       types:       types,
+                       reversed:    reversed,
+               }

Review Comment:
   this code can be removed now right?



##########
metadata.go:
##########
@@ -1332,15 +1360,60 @@ func (class *typeParserClassNode) asTypeInfo() TypeInfo 
{
                elem := class.params[1].class.asTypeInfo()
                return CollectionType{
                        NativeType: NativeType{
-                               typ: TypeMap,
+                               typ:   TypeMap,
+                               proto: class.proto,
                        },
                        Key:  key,
                        Elem: elem,
                }
        }
+       if strings.HasPrefix(class.name, UDT_TYPE) {
+               udtName, _ := hex.DecodeString(class.params[1].class.name)
+               fields := make([]UDTField, len(class.params)-2)
+               for i := 2; i < len(class.params); i++ {
+                       fieldName, _ := hex.DecodeString(*class.params[i].name)
+                       fields[i-2] = UDTField{
+                               Name: string(fieldName),
+                               Type: class.params[i].class.asTypeInfo(),
+                       }
+               }
+               return UDTTypeInfo{
+                       NativeType: NativeType{
+                               typ:   TypeUDT,
+                               proto: class.proto,
+                       },
+                       KeySpace: class.params[0].class.name,
+                       Name:     string(udtName),
+                       Elements: fields,
+               }
+       }
+       if strings.HasPrefix(class.name, TUPLE_TYPE) {
+               fields := make([]TypeInfo, len(class.params))
+               for i := 0; i < len(class.params); i++ {
+                       fields[i] = class.params[i].class.asTypeInfo()
+               }
+               return TupleTypeInfo{
+                       NativeType: NativeType{
+                               typ:   TypeTuple,
+                               proto: class.proto,
+                       },
+                       Elems: fields,
+               }
+       }
+       if strings.HasPrefix(class.name, VECTOR_TYPE) {
+               dim, _ := strconv.Atoi(class.params[1].class.name)
+               return VectorType{
+                       NativeType: NativeType{
+                               typ:   TypeCustom,
+                               proto: class.proto,
+                       },
+                       SubType:    class.params[0].class.asTypeInfo(),
+                       Dimensions: dim,
+               }
+       }

Review Comment:
   this code can be removed now right?



##########
helpers.go:
##########
@@ -162,47 +164,82 @@ func getCassandraBaseType(name string) Type {
        }
 }
 
-func getCassandraType(name string, logger StdLogger) TypeInfo {
+// Parses short CQL type representation to internal data structures.
+// Mapping of long Java-style type definition into short format is performed in
+// apacheToCassandraType function.
+func getCassandraType(name string, protoVer byte, logger StdLogger) TypeInfo {
        if strings.HasPrefix(name, "frozen<") {
-               return getCassandraType(strings.TrimPrefix(name[:len(name)-1], 
"frozen<"), logger)
+               return getCassandraType(strings.TrimPrefix(name[:len(name)-1], 
"frozen<"), protoVer, logger)
        } else if strings.HasPrefix(name, "set<") {
                return CollectionType{
-                       NativeType: NativeType{typ: TypeSet},
-                       Elem:       
getCassandraType(strings.TrimPrefix(name[:len(name)-1], "set<"), logger),
+                       NativeType: NewNativeType(protoVer, TypeSet),
+                       Elem:       
getCassandraType(strings.TrimPrefix(name[:len(name)-1], "set<"), protoVer, 
logger),
                }
        } else if strings.HasPrefix(name, "list<") {
                return CollectionType{
-                       NativeType: NativeType{typ: TypeList},
-                       Elem:       
getCassandraType(strings.TrimPrefix(name[:len(name)-1], "list<"), logger),
+                       NativeType: NewNativeType(protoVer, TypeList),
+                       Elem:       
getCassandraType(strings.TrimPrefix(name[:len(name)-1], "list<"), protoVer, 
logger),
                }
        } else if strings.HasPrefix(name, "map<") {
                names := 
splitCompositeTypes(strings.TrimPrefix(name[:len(name)-1], "map<"))
                if len(names) != 2 {
                        logger.Printf("Error parsing map type, it has %d 
subelements, expecting 2\n", len(names))
-                       return NativeType{
-                               typ: TypeCustom,
-                       }
+                       return NewNativeType(protoVer, TypeCustom)
                }
                return CollectionType{
-                       NativeType: NativeType{typ: TypeMap},
-                       Key:        getCassandraType(names[0], logger),
-                       Elem:       getCassandraType(names[1], logger),
+                       NativeType: NewNativeType(protoVer, TypeMap),
+                       Key:        getCassandraType(names[0], protoVer, 
logger),
+                       Elem:       getCassandraType(names[1], protoVer, 
logger),
                }
        } else if strings.HasPrefix(name, "tuple<") {
                names := 
splitCompositeTypes(strings.TrimPrefix(name[:len(name)-1], "tuple<"))
                types := make([]TypeInfo, len(names))
 
                for i, name := range names {
-                       types[i] = getCassandraType(name, logger)
+                       types[i] = getCassandraType(name, protoVer, logger)
                }
 
                return TupleTypeInfo{
-                       NativeType: NativeType{typ: TypeTuple},
+                       NativeType: NewNativeType(protoVer, TypeTuple),
                        Elems:      types,
                }
-       } else {
+       } else if strings.HasPrefix(name, "vector<") {
+               names := 
splitCompositeTypes(strings.TrimPrefix(name[:len(name)-1], "vector<"))
+               subType := getCassandraType(strings.TrimSpace(names[0]), 
protoVer, logger)
+               dim, _ := strconv.Atoi(strings.TrimSpace(names[1]))
+
+               return VectorType{
+                       NativeType: NewCustomType(protoVer, TypeCustom, 
VECTOR_TYPE),
+                       SubType:    subType,
+                       Dimensions: dim,
+               }
+       } else if strings.Index(name, "<") == -1 {
+               // basic type
                return NativeType{
-                       typ: getCassandraBaseType(name),
+                       proto: protoVer,
+                       typ:   getCassandraBaseType(name),
+               }
+       } else {
+               // udt
+               idx := strings.Index(name, "<")

Review Comment:
   This doesn't exist. You're creating this artificial "udt" short type with 
the complete udt definition but this doesn't exist in CQL. This function is 
being used to parse CQL short types returned by C* AND short types that are the 
result of our "translation" code so it doesn't make sense to add custom logic 
here that applies to types that are the result of our "translation" code only. 
The "translation" code should never result in short type names that don't exist 
in CQL.
   
   We have to handle UDT **long type** parsing **outside** of this function and 
this function should parse the udt name ONLY which is what C* returns in udt 
short types and then read the rest of the udt definition via system table.
   
   For the UDT short type parsing you can simply add a TODO since this is not 
really the scope of the PR. 
   
   For the purpose of this PR I think it's good enough to just handle UDT long 
type parsing outside of this function. You can still use this function for all 
types that are not UDT or custom though since UDTs and custom types are the 
only ones that can't be parsed in an equivalent way regardless of whether they 
are long or short (UDTs in short format don't have the complete definition and 
custom types in the short format can't be distinguished from a UDT). Whether it 
makes it easier to reuse this or just create a separate function to handle long 
types separately (and potentially getting rid of "translation" code) is up to 
you.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to