-
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] Determine approach to looping #29289
Comments
I prefer option 2. I feels pretty natural to write "for each item in this path, perform this statement". Something like
feels pretty natural from a syntax perspective. I don't know yet how we'd pass |
@evan-bradley I am curious if you've got a vision for how this solves #27820 |
It allows us to take the solution you outlined here #27820 (comment) and extend it to |
@evan-bradley I don't see yet how to apply the looping functionality to an editor that handles the looping itself. My current mental model for this feature is to loop over the items and reference individual items in the statement. With that model I don't see how we'd apply the loops to an editor like In my head the issue in #27820 is that we have no good way to pass only a specific capture group to the option Function parameter. It isn't clear to me yet how a looping construct in the language solves that problem. |
Sorry, I could have worded that better. What I mean to say is that you outlined how to accomplish #27820 on a single string using what already exists in OTTL. This means that if we can't offer this functionality cleanly from However, users are unable perform this operation across all items in a map since there's no way to loop, which would motivate us to make changes to the function parameters in I don't know that this solves #27820 so much as it would allow us to more carefully consider whether we think the tradeoff of function parameter complexity vs. statement complexity is worth it. The reason I brought it up is because it showcases how putting a lot of functionality inside Editors may have drawbacks. There are other issues that could also demonstrate this point. |
This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
hey folks - I spent a few hours prototyping an OTTL compiler + type system. I'd like to suggest avoiding imperative iteration and use something closer to list-comprehensions (python, typescript, e.g.). Specifically, I think you could have something like:
You have a lot of options for syntax, e.g.
I'm happy to help contribute this. I have a larger more formal proposal in addition. |
This feature will be useful for #31133 |
An update on this. Met with @TylerHelmuth and @evan-bradley - Working on a proposal for a comprehension-type syntax for collections. Current thinking is a generator type syntax mixed with existing collection features. So something like Expr2 - current scope of OTTL I'm still re-orienting myself around the Go code for a comprehensive design/proposal here, as we may need to do some lifting on how context works (at least internally in the evaluation). |
Component(s)
pkg/ottl
Is your feature request related to a problem? Please describe.
Looping over maps or lists is required to perform a common operation on each item. Currently we handle modifying these structures by having Editors that handle performing some operation while looping over the structure.
However, having editors abstract over looping sometimes presents difficulties when the operations need to be customizable. This requires putting a lot of parameters on the Editor to allow the user to change the operation they're looking to do. This situation can be currently seen in #27820, but has come up a number of times.
Describe the solution you'd like
Determine how we want to handle loops in OTTL. I see a few approaches here:
for key, val in attributes
orfor i, val in attributes["list"]
. I think this could be a good option between flexibility and complexity if done carefully.filter
,map
,reduce
, etc.) to allow handling these types. I think this would likely get too complicated too quickly.Describe alternatives you've considered
Restrict the use-cases the OTTL standard function suite supports and require users to define their own functions in more cases. I'd prefer to instead make it easier for OTTL to support a wide range of cases
Additional context
No response
The text was updated successfully, but these errors were encountered: