Add filtering to dot operations with field matching #33
Labels
No labels
bug
duplicate
enhancement/documentation
enhancement/feature
enhancement/organization
question
rejected
upstream
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
UserCurt/mpath#33
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?
Matching children can be too permissive in some circumstances as operations like
DotGlobor later-definedDotRegex(#4) can only select by name. This issue proposes adding filtering syntax to select a subset of matched names provided a condition. This would give more control to the user in selecting fields based on more than just the field name itself.The notation is not yet settled, but they would likely come directly after the field-matching operation, like in
/*[FILTER]. Some inspiration can be taken from syntax of other similar tools like XPath[____], JSONPath[?____], JMESPath[? ____ ].Ideas for conditions
The available conditions is not yet clear, but it can include things such as:
/*[type:struct],/*[type:table],/*[type:object],/*[type:CLASSNAME]: Select fields with values of a given type/*[type:container],/*[type:noncontainer]: Select fields whether or not they are container types/*[has:/X],/*[has:PATH]: Selects fields that have a child or given descendant chain. There may be some nuance where only some branches of the descendant chain are valid./*[has:>]/X/Y/Z: Selects fields that have the given descendant chain/*[value > 0],/*[(value<-3) || (value>3)],/*[value(1) < value(2)]: Select fields that satisfy some expression/*[has:/X && value(/X) > 0]: Some combined conditions may require short-circuiting to avoid errors/*[size(value, 2) == 3],/*[numel(value) > 2],/*[~isscalar(value)]: The expression could include function callsThe examples above only uses
valuefor the currently selected child, but there may be benefits to being able to select parents, ascendants, or descendants. For example:/users/*[value(/age)>=18]/namewould select users' names of those at least 18 years old./{Susan,Jane}/Children/*[value(/Height)>=value(/../../Height)]would select children of Susan and Jane who are taller than their motherOpen questions
.should be required or implicitDotExact, for example/X[/Z > 0]/Y[has:/*/X]Example
One use case is to select valid children only.
Without filtering,
*matchesA,B, andC, then/Xis attempted on each branch. The/B/Xbranch is non-traversable becauseBis not a container. The filter[has:/X]would excludeBfrom the list of fields because it does not satisfy the condition of having a childX.This would make it so users would not need to rely on
MissingPolicyto filter in-post. See #32 regarding traversing paths through non-containers.