Optionally keep paths that do not exist with resolve #11
Labels
No labels
bug
duplicate
enhancement/documentation
enhancement/feature
enhancement/organization
question
rejected
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
UserCurt/mpath#11
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This feature request is to optionally allow
mpath.resolveto return MPath Pointers that do not point to existing entries (i.e., the paths do not exist).The proposed solution is to replace the named argument
AllowEmptyFieldswith a new oneNullFieldwhich dictates behavior when a null field is encountered. When a field that does not exist is encountered, the behavior will be dictated by the value ofNullfield:omit-- Ignores the invalid/null path and excludes it from the resultmissing-- Replaces the invalid/null path with a missing Pointerretain-- Keeps the invalid/null patherror-- Gives an errorThere is some overlap in functionality between this proposal and
FillGapswith some nuanced differences when working with heterogeneous data structures. These details may not matter to the end user, so mergingFillGapswithNullFieldshould be considered.FillGapsmight need to be generalized to include missing fields:The open question is what option (named argument) should be provided so that the user can get this instead:
A related question: Should
/{A,B}/{X,Y,Z}(once set notation from #3 is implemented) behave identically to/*/*in this circumstance? I can see the argument how the fields X, Y, and Z must be checked for each branch A and B in the former, but for the later each * at each branch is considered independent and can match different fields. However, everything eventually has to be shaped anyways, so the second*effectively share the same pool of fields, suggesting these should behave the same. This line of reasoning suggestsFillGapsandNullFieldshould be merged somehow. That is, unless there is a use case otherwise?Some progress has been made on this issue but it is not yet complete.
Two notes:
resolvebe able to return paths that do not exist will help enablesetto create fields that do not exist.FillGapswas historically overloaded ingetto handle two distinct situations: Filling in gaps where paths were missing (via missing paths returned fromresolve) and filling in the gaps when there was a size mismatch. It was later split into the nowMissingPolicyandSizeMismatchPolicy.Relevant history around
resolve:137593eon2025-09-25:AllowEmptyMatchesandFillGapsoriginally introduced using logical policy.5df9c181on2025-10-10: This was changed whereAllowEmptyMatcheswas replaced withNullFieldinresolvewith more options, now supporting for"omit""missing","retain","error".70f5380on2025-10-16: Prior to this point,NullFielddetermined what to do when a missing path branch was found, whileFillGapsdetermined whether post-reshape rectangular holes were allowed. In this commit,NullFieldwas renamed (and oldAllowEmptyMatcheslanguage) toMissingPolicyinresolve, andFillGapswas removed fromresolve.The new
MissingPolicywasn't fully functional at this time but was addressed in later commits:bd5ddcd: retained path reconstruction for missing resolved slotsdf3e54f: heterogeneous struct-array missing-policy bug65af1e0: missing branch handling84f9e78:DotSetwithMissingPolicy="retain"including missing fieldsThe new
MissingPolicyapproach was then used withgetand other functions:90a851fon2026-06-11: While some changes were being underwent withresolve,getwas disabled. This commit re-enabledget.70ff089on2026-06-13: Policy semantics ingetbecame better controlled by havingMissingPolicyfor handling missing paths andSizeMismatchPolicyfor handling mismatched sizes in the results.206e68aand83e1046on2026-06-13:setandremovewere modified to useMissingPolicybut with different options based on what was reasonable for those functions:setaccepted"create","ignore", and"error", andremoveaccepted"ignore"and"error".This issue is not fully addressed yet. Below is an example that does not return results as expected:
The expected results would be:
The issue has been addressed in
fdd36bb.Current behavior from the example in the comment above gives the expected result shapes:
MissingPolicy="omit"->1×2MissingPolicy="missing"->2×2MissingPolicy="retain"->2×2Related but more specific bugs are being tracked separately:
set#10