Skip to content

Commit 473da51

Browse files
Bugfix/issue 61 support complex map type (#65)
porting ClickHouse/clickhouse-go#554
1 parent d47a4ac commit 473da51

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/column/map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Map struct {
3636

3737
func (col *Map) parse(t Type) (_ Interface, err error) {
3838
col.chType = t
39-
if types := strings.Split(t.params(), ","); len(types) == 2 {
39+
if types := strings.SplitN(t.params(), ",", 2); len(types) == 2 {
4040
if col.keys, err = Type(strings.TrimSpace(types[0])).Column(); err != nil {
4141
return nil, err
4242
}

tests/map_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func TestMap(t *testing.T) {
5454
, Col3 map(string, uint64)
5555
, Col4 array(map(string, string))
5656
, Col5 map(low_cardinality(string), low_cardinality(uint64))
57+
, Col6 map(string, array(map(string, float64)))
5758
)
5859
`
5960
defer func() {
@@ -79,22 +80,28 @@ func TestMap(t *testing.T) {
7980
"key_col_5_1": 100,
8081
"key_col_5_2": 200,
8182
}
83+
col6Data = map[string][]map[string]float64{
84+
"key1": {{"key1-1-1": 11.1, "key1-1-2": 11.2}, {"key1-2-1": 12.1}},
85+
"key2": {{"key2-1-1": 21.1}, {"key2-2-1": 22.1}, {"key2-3-1": 23.1, "key2-3-2": 23.2, "key2-3-3": 23.3}},
86+
}
8287
)
83-
if err := batch.Append(col1Data, col2Data, col3Data, col4Data, col5Data); assert.NoError(t, err) {
88+
if err := batch.Append(col1Data, col2Data, col3Data, col4Data, col5Data, col6Data); assert.NoError(t, err) {
8489
if assert.NoError(t, batch.Send()) {
8590
var (
8691
col1 map[string]uint64
8792
col2 map[string]uint64
8893
col3 map[string]uint64
8994
col4 []map[string]string
9095
col5 map[string]uint64
96+
col6 map[string][]map[string]float64
9197
)
92-
if err := conn.QueryRow(ctx, "SELECT (* except _tp_time) FROM test_map WHERE _tp_time > earliest_ts() LIMIT 1").Scan(&col1, &col2, &col3, &col4, &col5); assert.NoError(t, err) {
98+
if err := conn.QueryRow(ctx, "SELECT (* except _tp_time) FROM test_map WHERE _tp_time > earliest_ts() LIMIT 1").Scan(&col1, &col2, &col3, &col4, &col5, &col6); assert.NoError(t, err) {
9399
assert.Equal(t, col1Data, col1)
94100
assert.Equal(t, col2Data, col2)
95101
assert.Equal(t, col3Data, col3)
96102
assert.Equal(t, col4Data, col4)
97103
assert.Equal(t, col5Data, col5)
104+
assert.Equal(t, col6Data, col6)
98105
}
99106
}
100107
}

0 commit comments

Comments
 (0)