Skip to content

Commit

Permalink
Fix metadata parser for composite collections (apache#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
beltran authored and Zariel committed Sep 13, 2018
1 parent e898b2b commit 864d590
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 1 addition & 5 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
18 changes: 18 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 864d590

Please sign in to comment.