-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[pkg/ottl] support merging multiple maps via merge_maps() function #37343
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
base: main
Are you sure you want to change the base?
Conversation
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
not stale |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
5e1f311
to
1058473
Compare
f4df84c
to
6014094
Compare
@@ -20,8 +20,9 @@ const ( | |||
|
|||
type MergeMapsArguments[K any] struct { | |||
Target ottl.PMapGetter[K] | |||
Source ottl.PMapGetter[K] | |||
Strategy string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're looking at breaking this, should we make the strategy optional and default to "upsert"? It would be nice if we could keep source
as the second argument and just append "sources" to the end.
If we kept sources
as the last argument, we could even avoid a breaking change here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be clear, are you suggesting:
type MergeMapsArguments[K any] struct {
Target ottl.PMapGetter[K]
Source ottl.PMapGetter[K]
Strategy ottl.Optional[string] - default to upsert
Sources ottl.Optional[ottl.PMapSliceGetter[K]] - default to empty
}
Why don't then keep the Strategy
as it is and the only change would be adding an optional sources
parameter at the end?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't then keep the Strategy as it is and the only change would be adding an optional sources parameter at the end?
If we do that, then we can't make Source
optional and we would need to figure out how to reconcile both Source
and Sources
being set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so this is the expected state?
type MergeMapsArguments[K any] struct {
Target ottl.PMapGetter[K]
Source ottl.Optional[ottl.PMapGetter[K]]
Strategy ottl.Optional[string] - default to upsert
Sources ottl.Optional[ottl.PMapSliceGetter[K]] - default to empty
}
That means, all of the parameters except the target are optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that looks right. One of either Source
or Sources
would be required to be set though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adapted, should be ready for a re-review
0121078
to
c805bf3
Compare
I think we can put this PR on hold for a bit while this one is not complete. If we end up merging that PR as it's right now, I think we wouldn't need to add the new type Sources ottl.Optional[[]ottl.PMapGetter[K]] |
Can you be more specific about the solution you are proposing? In my opinion, we still need to support a SliceGetter in this case (or adapt PMapGetter), since there is no possibility that this type would accept slices. Thanks! |
The |
The PR you linked does not adapt You actually need to introduce a functionality that handles the extraction of slice of maps into []pcommon.Map, therefore introduce a separate This part is not handled in |
c805bf3
to
55d5a8d
Compare
I'm sorry, but I'm still failing to understand why we would need a specific type for that, since OTTL now supports maps inside slices. The only thing I think it would change is the way we access the data, for example, using the suggested slice of maps, it would looks like this: type MergeMapsArguments[K any] struct {
...
Sources ottl.Optional[[]ottl.PMapGetter[K]]
}
func mergeMaps[K any](target ottl.PMapGetter[K], source ottl.Optional[ottl.PMapGetter[K]], strategy ottl.Optional[string], sources ottl.Optional[[]ottl.PMapGetter[K]]) (ottl.ExprFunc[K], error) {
....
if !sources.IsEmpty() {
sourcesMapsSlice := sources.Get()
for _, sourceGetter := range sourcesMapsSlice {
val, err := sourceGetter.Get(ctx, tCtx)
if err != nil {
return nil, err
}
if err := merge(mergeStrategy, &val, &targetMap); err != nil {
return nil, err
}
}
}
....
} That should support not only literal values, but any map getter, including paths:
Am I missing something? |
I made exactly these changes previously and it won't work due to reasons I mentioned. Did you tried out the code snipped you sent me? If not, please do so. I might be missing something, but this solution won't work in my opinion |
Signed-off-by: odubajDT <[email protected]>
Signed-off-by: odubajDT <[email protected]>
Signed-off-by: odubajDT <[email protected]>
Signed-off-by: odubajDT <[email protected]>
Signed-off-by: odubajDT <[email protected]>
db1a8f8
to
929d6eb
Compare
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Description
Support merging more than 2 maps via
merge_maps()
functionLink to tracking issue
Fixes #32954