Skip to content

Commit

Permalink
Revert unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-antoniak committed Oct 29, 2024
1 parent e21b496 commit 24daa93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
33 changes: 3 additions & 30 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,31 +337,14 @@ func splitCompositeTypes(name string, typeOpen int32, typeClose int32) []string

// Convert long Java style type definition into the short CQL type names.
func apacheToCassandraType(t string) string {
t = strings.Replace(t, apacheCassandraTypePrefix, "", -1)
t = strings.Replace(t, "(", "<", -1)
t = strings.Replace(t, ")", ">", -1)
types := strings.FieldsFunc(t, func(r rune) bool {
return r == '<' || r == '>' || r == ','
})
for i := 0; i < len(types); i++ {
class := strings.TrimSpace(types[i])
// UDT fields are represented in format {field id}:{class}, example 66697273745f6e616d65:org.apache.cassandra.db.marshal.UTF8Type
// Do not override hex encoded field names
idx := strings.Index(class, ":")
class = class[idx+1:]
val := ""
if strings.HasPrefix(class, apacheCassandraTypePrefix) {
act := getApacheCassandraType(class)
val = act.String()
switch act {
case TypeUDT:
i += 2 // skip next two parameters (keyspace and type ID), do not attempt to resolve their type
case TypeCustom:
val = getApacheCassandraCustomSubType(class)
}
} else {
val = class
}
t = strings.Replace(t, class, val, -1)
for _, typ := range types {
t = strings.Replace(t, typ, getApacheCassandraType(typ).String(), -1)
}
// This is done so it exactly matches what Cassandra returns
return strings.Replace(t, ",", ", ", -1)
Expand Down Expand Up @@ -424,16 +407,6 @@ func getApacheCassandraType(class string) Type {
}
}

// Dedicated function parsing known special subtypes of CQL custom type.
// Currently, only vectors are implemented as special custom subtype.
func getApacheCassandraCustomSubType(class string) string {
switch strings.TrimPrefix(class, apacheCassandraTypePrefix) {
case "VectorType":
return "vector"
}
return "custom"
}

func (r *RowData) rowMap(m map[string]interface{}) {
for i, column := range r.Columns {
val := dereference(r.Values[i])
Expand Down
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func TestGetCassandraType_Set(t *testing.T) {
typ := getCassandraType("set<text>", 4, &defaultLogger{})
typ := getCassandraType("set<text>", protoVersion4, &defaultLogger{})
set, ok := typ.(CollectionType)
if !ok {
t.Fatalf("expected CollectionType got %T", typ)
Expand Down

0 comments on commit 24daa93

Please sign in to comment.