Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 4ca0da5

Browse files
authored
Merge pull request ClickHouse#207 from cw9/master
Support inserting [][]byte to Array(String) column
2 parents 262637f + 57e1e41 commit 4ca0da5

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

clickhouse_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,18 @@ func TestArrayArrayT(t *testing.T) {
12281228
if !assert.NoError(t, err) {
12291229
return
12301230
}
1231+
_, err = stmt.Exec(
1232+
[][][]byte{
1233+
[][]byte{[]byte("AA")},
1234+
[][]byte{[]byte("BB")},
1235+
[][]byte{[]byte("C4C")},
1236+
},
1237+
[][]byte{[]byte("XX"), []byte("YY")},
1238+
[]int32{4, 5, 6},
1239+
)
1240+
if !assert.NoError(t, err) {
1241+
return
1242+
}
12311243
} else {
12321244
return
12331245
}

lib/column/array.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (array *Array) read(decoder *binary.Decoder, ln int) (interface{}, error) {
5959
return slice.Interface(), nil
6060
}
6161

62+
func (array *Array) Depth() int {
63+
return array.depth
64+
}
65+
6266
func parseArray(name, chType string, timezone *time.Location) (*Array, error) {
6367
if len(chType) < 11 {
6468
return nil, fmt.Errorf("invalid Array column type: %s", chType)

lib/column/column.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Column interface {
1616
Read(*binary.Decoder) (interface{}, error)
1717
Write(*binary.Encoder, interface{}) error
1818
defaultValue() interface{}
19+
Depth() int
1920
}
2021

2122
func Factory(name, chType string, timezone *time.Location) (Column, error) {

lib/column/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ func (base *base) defaultValue() interface{} {
5454
func (base *base) String() string {
5555
return fmt.Sprintf("%s (%s)", base.name, base.chType)
5656
}
57+
58+
func (base *base) Depth() int {
59+
return 0
60+
}

lib/data/block.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func (block *Block) Read(serverInfo *ServerInfo, decoder *binary.Decoder) (err e
9696
}
9797

9898
func (block *Block) writeArray(column column.Column, value reflect.Value, num, level int) error {
99+
if level > column.Depth() {
100+
return column.Write(block.buffers[num].Column, value.Interface())
101+
}
99102
switch {
100103
case value.Kind() == reflect.Slice:
101104
if len(block.offsets[num]) < level {

0 commit comments

Comments
 (0)