ClickHouse / clickhouse-go

Golang driver for ClickHouse
Apache License 2.0
2.88k stars 553 forks source link

Batch insert into columns of type Array(Array..)) fails for interfaced slices #1349

Closed phil-schreiber closed 2 months ago

phil-schreiber commented 3 months ago

Observed

  1. dynamically retrieving values from protobufs
  2. create []interface{} for protobuf lists
  3. Preparing Insert
  4. appending to batch
  5. AppendRow fails with: clickhouse [AppendRow]: converting reflect.Value to Array is unsupported

Expected behaviour

AppendRow and insert succeeds

Code example

package main

import (
    "context"
    "fmt"
    "github.com/ClickHouse/clickhouse-go/v2"
)

func main() {
    conn, _ := clickhouse.Open(&clickhouse.Options{
        Protocol: clickhouse.Native,
        Addr:     []string{fmt.Sprintf("%s:%d", "127.0.0.1", 9001)},
        Auth: clickhouse.Auth{
            Database: "default",
            Username: "admin",
            Password: "123",
        },
    })

    conn.Exec(context.Background(), "CREATE TABLE IF NOT EXISTS default.array_test (Col1 Array(Array(String))) Engine = Memory")
    strings := []string{"foo", "bar"}
    stringsWorking := [][]string{strings}

    var insertValue []interface{}
    insertValue = append(insertValue, strings)

    batch, err := conn.PrepareBatch(context.Background(), "INSERT INTO default.array_test Col1 VALUES (?)")
    if err != nil {
        panic(err)
    }
    err = batch.Append(stringsWorking)
    if err != nil {
        panic(err)
    }

    // This fails !!!
    err = batch.Append(insertValue)
    if err != nil {
        panic(err)
    }
}

Error log

clickhouse [AppendRow]: converting reflect.Value to Array is unsupported

Details

Environment