-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Provide built-in function (or other mean) to check if collection x includes collection y #4358
Comments
Looks like a good built-in function candidate. A couple minor thoughts:
|
As for namespacing, agreed. I wonder though if it can be seen as confusing that an |
I'd think { x | subset(x, {1, 2}) } == { {}, {1}, {2}, {1, 2} } For correctness reasons of our current implementations, it would be cool if there was a second relation. Currently, we only have |
I can kinda see the coolness factor 🙂 I guess if it works the same way (and performs about the same) when provided a fixed value, why not! How would this work when a subset is not matched though? Would it return undefined? IIRC walk always returns something, so it's never "falsy".. or can it be? |
A call to
Same would go for a subset relation. |
Thanks! 👍 |
This implements the new object.subset() builtin. Based on my benchmarking, this offers a 2.77x speedup compared to implementing the same thing in pure Rego, and is also easier to read. Fixes open-policy-agent#4358 Signed-off-by: Charles Daniels <[email protected]>
This implements the new object.subset() builtin. Based on my benchmarking, this offers a 2.77x speedup compared to implementing the same thing in pure Rego, and is also easier to read. Fixes #4358 Signed-off-by: Charles Daniels <[email protected]>
Several people have asked me recently how to check if a composite value (i.e. collection) is included in another collection. While this is obviously doable for any composite value type (set, array, object) already, it isn't obvious how to do it!
Think subset but generalized to work with any collection type. Example below using
in
operator, but this is obviously not working code:It would be a useful addition if Rego provided a built-in, or had a current operator extended, for quickly answer these types of "subset" queries:
When bouncing this idea off of @srenatus , he suggested the proposed elipsis operator matching might be used to accomplish this:
Although it's not as clear how that would work when provided values stored in variables rather than literals like provided above. We also discussed some ideas of extending
in
,some
orevery
to accomplish this, but I think we're both leaning towards a new built-in function being the easiest way to accomplish this. Definitely open to suggestions though!Since I realize some people might find this while searching for a solution for how to accomplish this currently, here's some ways you could do it (and I think, pretty good evidence for why this should be made simpler):
Sets
Arrays
Objects
The text was updated successfully, but these errors were encountered: