ClickHouse/ch-go

[QUESTION] How to call AppendKV when ColMap is wrapped in an array

OrangeFlag opened this issue · 1 comments

Hello!
Thank you for the wonderful library.

Could you please help me? I want to call the method AppendKV for ColMap that is wrapped inside a ColArr. My goal is to set a specific order of keys in each of these maps.

Here is an example of what I'm trying to achieve:

eventsAttr := proto.NewArray(
  proto.NewMap[string, string](
    new(proto.ColStr).LowCardinality(),
    new(proto.ColStr),
  ),
)

eventsAttrArr := make([][]proto.KV[string, string], 0, len(events))
eventsAttrArr = append(eventsAttrArr, []proto.KV[string, string]{
  {Key: "one", Value: "specific"},
  {Key: "two", Value: "order"},
})

eventsAttrArr = append(eventsAttrArr, []proto.KV[string, string]{
  {Key: "one", Value: "totally"},
  {Key: "two", Value: "specific"},
  {Key: "three", Value: "order"},
})

// somehow add all eventsAttrArr to eventsAttr (?)

Could you provide an example of how this can be done?

Thank you in advance for your assistance!

P.S.
Is it maybe possible to achieve this using *proto.ColArr[[]proto.KV]? Will it serialize correctly to Array(Map(LowCardinality(String), String))?

Used something like this is

         eventsAttr := proto.NewArray(
		proto.NewMap[string, string](
			new(proto.ColStr).LowCardinality(),
			new(proto.ColStr),
		),
	)
	for _, event := range events {
		attrs := make([]proto.KV[string, string], 0, len(event.Attributes))
		for _, kv := range event.Attributes {
			attrs = append(attrs, proto.KV[string, string]{Key: string(kv.Key), Value: value})
		}
		eventsAttr.Data.(*proto.ColMap[string, string]).AppendKV(attrs)
	}
	eventsAttr.Offsets = append(b.eventsAttr.Offsets, uint64(b.eventsAttr.Data.Rows()))

Wouldn't it be convenient for Array to contain methods AddElement and NextRow?