-
Notifications
You must be signed in to change notification settings - Fork 307
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
cue: improve documentation for Value.UnifyAccept #2300
Comments
I'm not altogether certain there isn't a bug lurking here given that method doesn't have tests. |
Oops, that sent early. Thanks for the report, @kortschak. |
Thanks. I'm not sure that #454 does exactly what I was looking for since it requires that fields be missing as opposed to the situation I have where I'd like explicitly not missing and disagreeing fields to be ignored, unless I'm missing something in that proposal for how to do that. |
Issue #2300 Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: If00caaad07ccd7519aeb7f2a8bdeb187a5854d93 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/556193 TryBot-Result: CUEcueckoo <cueckoo+gerrithub@cuelang.org> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Paul Jolly <paul@myitcv.io>
@kortschak with a downcast, you can take a CUE struct and remove any fields which are not in another struct. Roger added an example in #454 (comment) which I find useful. Going from the example you shared at the top, here are my thoughts on your scenario: https://tip.cuelang.org/play/?id=qFlvpZpJztc#cue@export@cue If you want to simply omit the field If you want to instead omit everything except a set of fields (what you could call an "allowlist" filter instead of a "blocklist"), then I think the third approach with downcasting would be better. It really depends on whether your data fields are a well-defined set or not. |
I'm going to remove this issue from the v0.6.0 milestone, since we want to get that out very soon, and we're focusing on siginficant regressions and bugs, such as panics or bad output. I'm more than happy to help unblock you regardless, of course :) |
Thanks @mvdan. I'm not blocked by this — I am working around it — but yes, the |
@kortschak in your original description, you have two values (which I will refer to as
Do you know the schema of Linking back to my thinking on how/why downcast might be related, therefore consider: https://tip.cuelang.org/play/?id=U2kBHrwp3KP#cue@export@cue If, however, you are looking for something more "automatic" where nothing is known about Are you able to share a bit more context on the "inputs" |
@myitcv The types and the skeleton of the schema that I'm using are here https://go.dev/play/p/2nyCaScb9O7. There are a few other parts, but they are largely irrelevant to this issue. The |
Thanks for sharing this. To further help my understanding, what does it mean to unify a |
Oh, sorry, that is a crucial part that I missed out. The application takes configuration snippets (as TOML) and aggregates them in to a single configuration (a valid |
Ah I see now. In which case I would suggest @mvdan's approach of The reason downcast will, in general, be more useful is that the "removal" of a field might need to occur at a nested point, in which case specifying "recursive" comprehensions gets messy very fast. |
Thanks. At the moment I'm just removing the field in Go before the validation and then replacing after. This is ugly, but simple. |
I've added a comment to #943 so that it is considered as part of that batch of builtins. We are planning to look through that list as part of the v0.7.0 changes, so will know more on timings/target release then. |
Just want to register a general interest in builtins in this area. I realize there may be nuanced differences, but when i look at This could be quite valuable for reducing copypasta in some of our user flows. |
With one important distinction to at least my understanding: @sdboyer thanks for registering the interesting. I suggest we continue the conversation over in #943. |
What version of CUE are you using (
cue version
)?Not using
cue
as an executable but rather via the Go API.Does this issue reproduce with the latest stable release?
Yes
What did you do?
Using the Go API I would like to be able to unify a set of values while ignoring some fields that are only transiently generated but useful to retain for logging purposes.
For example if I have
I would like to be able to resolve this to something like
or similar with the sum field omitted.
It looks to me from the documentation that something like this is supported by
cue.Value.UnifyAccept
, but how to use it to do this is unclear and I have not been able to get it to work in my experiments. Can the documentation be clarified for this?What did you expect to see?
Clear explanation of how to use
UnifyAccept
.What did you see instead?
Limited explanation. I was able to find one use of it in the tree and no tests, so it is difficult to know how to use it, or even whether my interpretation that it is usable for this is correct.
The text was updated successfully, but these errors were encountered: