-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[pkg/ottl] Support dynamic indexing #36719
base: main
Are you sure you want to change the base?
Changes from all commits
d965519
02b72ec
fda69bc
97b369c
bc1dc8e
28ffc31
ee9878d
db9ec8b
09a6ab2
b3bc495
2a2e8c4
31c45d6
63b2fe7
0cb42da
d8af6b1
dde8935
51c0d1f
b8c4622
b62391b
5e92cc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: pkg/ottl | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: "Support dynamic indexing of maps and slices." | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [36644] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -46,6 +46,7 @@ var _ ottl.Key[any] = &TestKey[any]{} | |||||
type TestKey[K any] struct { | ||||||
S *string | ||||||
I *int64 | ||||||
P ottl.Getter[K] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same here, I think a |
||||||
} | ||||||
|
||||||
func (k *TestKey[K]) String(_ context.Context, _ K) (*string, error) { | ||||||
|
@@ -55,3 +56,7 @@ func (k *TestKey[K]) String(_ context.Context, _ K) (*string, error) { | |||||
func (k *TestKey[K]) Int(_ context.Context, _ K) (*int64, error) { | ||||||
return k.I, nil | ||||||
} | ||||||
|
||||||
func (k *TestKey[K]) ExpressionGetter(_ context.Context, _ K) (ottl.Getter[K], error) { | ||||||
return k.P, nil | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,7 +22,11 @@ func GetSliceValue[K any](ctx context.Context, tCtx K, s pcommon.Slice, keys []o | |||||
return nil, err | ||||||
} | ||||||
if i == nil { | ||||||
return nil, fmt.Errorf("non-integer indexing is not supported") | ||||||
resInt, err := FetchValueFromExpression[K, int64](ctx, tCtx, keys[0]) | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("non-integer indexing is not supported") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think at a minimum we should wrap the underlying error, but we should also consider rewording this message, since I'm not sure a failure in |
||||||
} | ||||||
i = resInt | ||||||
} | ||||||
|
||||||
idx := int(*i) | ||||||
|
@@ -44,7 +48,11 @@ func SetSliceValue[K any](ctx context.Context, tCtx K, s pcommon.Slice, keys []o | |||||
return err | ||||||
} | ||||||
if i == nil { | ||||||
return fmt.Errorf("non-integer indexing is not supported") | ||||||
resInt, err := FetchValueFromExpression[K, int64](ctx, tCtx, keys[0]) | ||||||
if err != nil { | ||||||
return fmt.Errorf("non-integer indexing is not supported") | ||||||
} | ||||||
i = resInt | ||||||
} | ||||||
|
||||||
idx := int(*i) | ||||||
|
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.
It would be nice to make this more explicit what's happening here, if a user ever hits this error we should try to give them all the relevant information we have. If possible, it would also be nice to print the type of
T
here so we can make it clear what type of key was expected.