Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OrangeFlag opened this issue Jul 31, 2024 · 1 comment
Open

Comments

@OrangeFlag
Copy link

OrangeFlag commented Jul 31, 2024

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))?

@OrangeFlag
Copy link
Author

OrangeFlag commented Aug 14, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant