yq/pkg/yqlib/operator_union.go

37 lines
1.1 KiB
Go
Raw Normal View History

2020-11-03 23:48:43 +00:00
package yqlib
2020-10-17 11:10:47 +00:00
func unionOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
2021-09-05 01:07:40 +00:00
log.Debug("unionOperator")
log.Debug("context: %v", NodesToString(context.MatchingNodes))
lhs, err := d.GetMatchingNodes(context, expressionNode.Lhs)
2020-10-17 11:10:47 +00:00
if err != nil {
return Context{}, err
2020-10-17 11:10:47 +00:00
}
2021-09-05 01:07:40 +00:00
log.Debug("lhs: %v", NodesToString(lhs.MatchingNodes))
log.Debug("rhs input: %v", NodesToString(context.MatchingNodes))
log.Debug("rhs: %v", expressionNode.Rhs.Operation.toString())
rhs, err := d.GetMatchingNodes(context, expressionNode.Rhs)
2021-09-05 01:07:40 +00:00
2020-10-17 11:10:47 +00:00
if err != nil {
return Context{}, err
2020-10-17 11:10:47 +00:00
}
2021-09-05 01:07:40 +00:00
log.Debug("lhs: %v", lhs.ToString())
log.Debug("rhs: %v", rhs.ToString())
// this can happen when both expressions modify the context
// instead of creating their own.
/// (.foo = "bar"), (.thing = "cat")
if rhs.MatchingNodes != lhs.MatchingNodes {
for el := rhs.MatchingNodes.Front(); el != nil; el = el.Next() {
node := el.Value.(*CandidateNode)
log.Debug("processing %v", NodeToString(node))
lhs.MatchingNodes.PushBack(node)
}
2020-10-17 11:10:47 +00:00
}
2021-09-05 01:07:40 +00:00
log.Debug("all together: %v", lhs.ToString())
2020-10-17 11:10:47 +00:00
return lhs, nil
}