Skip to content

Commit

Permalink
fix(bagtype): fix cqlpretty for list kind
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kropachev committed Jun 8, 2023
1 parent 53f384b commit 28478f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pkg/coltypes/bag.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ func (ct *BagType) CQLPretty(query string, value []interface{}) (string, int) {
panic(fmt.Sprintf("set cql pretty, unknown type %v", ct))
}
s := reflect.ValueOf(value[0])
vv := "{"
op, cl := "[", "]"
if ct.Kind == "set" {
op, cl = "{", "}"

}
vv := op
vv += strings.Repeat("?,", s.Len())
vv = strings.TrimRight(vv, ",")
vv += "}"
vv += cl
for i := 0; i < s.Len(); i++ {
vv, _ = ct.Type.CQLPretty(vv, []interface{}{s.Index(i).Interface()})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/coltypes/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ var prettytests = []struct {
},
query: "SELECT * FROM tbl WHERE pk0=?",
values: []interface{}{[]string{"a", "b"}},
expected: "SELECT * FROM tbl WHERE pk0={'a','b'}",
expected: "SELECT * FROM tbl WHERE pk0=['a','b']",
},
{
typ: &coltypes.MapType{
Expand Down

0 comments on commit 28478f6

Please sign in to comment.