Browse Source

Fix metadata parser for composite collections (#1185)

Jaume Marhuenda 7 years ago
parent
commit
864d590845
2 changed files with 19 additions and 5 deletions
  1. 1 5
      helpers.go
  2. 18 0
      helpers_test.go

+ 1 - 5
helpers.go

@@ -132,11 +132,7 @@ func getCassandraType(name string) TypeInfo {
 			Elem:       getCassandraType(strings.TrimPrefix(name[:len(name)-1], "list<")),
 		}
 	} else if strings.HasPrefix(name, "map<") {
-		names := strings.Split(strings.TrimPrefix(name[:len(name)-1], "map<"), ", ")
-		if len(names) != 2 {
-			panic(fmt.Sprintf("invalid map type: %v", name))
-		}
-
+		names := strings.SplitN(strings.TrimPrefix(name[:len(name)-1], "map<"), ", ", 2)
 		return CollectionType{
 			NativeType: NativeType{typ: TypeMap},
 			Key:        getCassandraType(names[0]),

+ 18 - 0
helpers_test.go

@@ -59,6 +59,24 @@ func TestGetCassandraType(t *testing.T) {
 				},
 			},
 		},
+		{
+			"frozen<map<text, frozen<list<frozen<tuple<int, int>>>>>>", CollectionType{
+				NativeType: NativeType{typ: TypeMap},
+
+				Key: NativeType{typ: TypeText},
+				Elem: CollectionType{
+					NativeType: NativeType{typ: TypeList},
+					Elem: TupleTypeInfo{
+						NativeType: NativeType{typ: TypeTuple},
+
+						Elems: []TypeInfo{
+							NativeType{typ: TypeInt},
+							NativeType{typ: TypeInt},
+						},
+					},
+				},
+			},
+		},
 	}
 
 	for _, test := range tests {