go-clickhouse
go-clickhouse copied to clipboard
panic: unsupported ClickHouse type="Map(String, String)"
My Model
type Video struct {
ch.CHModel `ch:"partition:toYYYYMM(time)"`
ID uint64
Title string `ch:""`
Time time.Time `ch:",pk"`
Meta []uint64 `ch:"type:Array(UInt64)"`
Chapter map[string]string `ch:"type:Map(String,String)"`
}
video := database.Video{
ID: 1,
Title: "Video 1",
Time: time.Now(),
Meta: []uint64{10, 10, 10, 10},
Chapter: map[string]string{
"hello1": "hello",
"hello": "hello",
"title": "title",
},
}
db.NewInsert().Model(&video).Exec(ctx)
panic: unsupported ClickHouse type="Map(String, String)"
goroutine 1 [running]: github.com/uptrace/go-clickhouse/ch/chschema.goType({0xc0000a4030, 0x13}) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/chschema/types.go:307 +0x6ce github.com/uptrace/go-clickhouse/ch/chschema.NewColumnFromCHType({0xc0000a4030, 0x13}, 0xc00009a1e0?) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/chschema/column.go:54 +0x28 github.com/uptrace/go-clickhouse/ch/chschema.(*Block).Column(0xc00009c280, {0xc00009a1e0, 0x7}, {0xc0000a4030, 0x13}) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/chschema/block.go:46 +0xd4 github.com/uptrace/go-clickhouse/ch.(*DB).readBlock.func1() /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/proto.go:515 +0x16e github.com/uptrace/go-clickhouse/ch/chproto.(*Reader).WithCompression(0xc00009c000, 0x1, 0x100e4a7?) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/chproto/reader.go:44 +0x53 github.com/uptrace/go-clickhouse/ch.(*DB).readBlock(0xc0002c8050, 0xc00009c000, 0xc00009c280, 0x1) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/proto.go:481 +0x8f github.com/uptrace/go-clickhouse/ch.(*DB).readSampleBlock(0x13c3820?, 0xc00009c000) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/proto.go:382 +0x12c github.com/uptrace/go-clickhouse/ch.(*DB)._insert.func1.2(0xc000094000?) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/db.go:405 +0x25 github.com/uptrace/go-clickhouse/ch/chpool.(*Conn).WithReader(0xc0000a0000, {0x131b410?, 0xc00001e0c0?}, 0x13b2c64?, 0xc00035fb50) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/chpool/conn.go:70 +0x67 github.com/uptrace/go-clickhouse/ch.(*DB)._insert.func1(0xc0000a0000) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/db.go:404 +0x12b github.com/uptrace/go-clickhouse/ch.(*DB)._withConn(0xc0002c8050, {0x131b410?, 0xc00001e0c0}, 0xc00035fcf8) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/db.go:219 +0x1ec github.com/uptrace/go-clickhouse/ch.(*DB).withConn(0xc0002c8050, {0x131b410?, 0xc00001e0c0?}, 0x12?) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/db.go:176 +0x28 github.com/uptrace/go-clickhouse/ch.(*DB)._insert(0xc0000922a0?, {0x131b410?, 0xc00001e0c0?}, {0x1000?, 0x1000?}, {0xc0000b5000?, 0x14?}, 0x1000?) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/db.go:396 +0x8f github.com/uptrace/go-clickhouse/ch.(*DB).insert(0xc0002c8050, {0x131b410, 0xc00001e0c0}, {0x131afa0, 0xc0000922a0}, {0xc0000b5000, 0x46}, {0xc000092090, 0x5, 0x6}) /Users/sohelmia/go/pkg/mod/github.com/uptrace/[email protected]/ch/db.go:383 +0x145
I'm having the same issue. This would be nice to add support as this is the datatype for storing attributes per the OTEL spec.
Map(String, String)
is just syntactic sugar for creating 2 separate columns keys
and values
. Here is what we use at Uptrace instead.
@vmihailenco - while it may be syntactic sugar, it is kind of nice to have it and ideally, it'd be nice to not change the schema.
How difficult would it be to add support to this library? That's my blocker for using this over the official Clickhouse client. I'd be happy to submit a PR for this if you can provide any pointers.
@et here you go - https://github.com/uptrace/go-clickhouse/pull/57. The hard part is to figure out how to implement reading/writing map[string]string
using ClickHouse native protocol (ReadFrom/WriteTo methods). Most likely https://github.com/ClickHouse/clickhouse-go already knows how to do that so you can also try to ask for help there.