2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-17 11:10:47 +00:00
|
|
|
|
2022-01-14 03:55:25 +00:00
|
|
|
import "container/list"
|
|
|
|
|
2021-02-02 07:17:59 +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))
|
2021-02-02 07:17:59 +00:00
|
|
|
lhs, err := d.GetMatchingNodes(context, expressionNode.Lhs)
|
2020-10-17 11:10:47 +00:00
|
|
|
if err != nil {
|
2021-02-02 07:17:59 +00:00
|
|
|
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())
|
2021-02-02 07:17:59 +00:00
|
|
|
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 {
|
2021-02-02 07:17:59 +00:00
|
|
|
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())
|
|
|
|
|
2022-01-14 03:55:25 +00:00
|
|
|
results := lhs.ChildContext(list.New())
|
|
|
|
for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() {
|
|
|
|
node := el.Value.(*CandidateNode)
|
|
|
|
results.MatchingNodes.PushBack(node)
|
|
|
|
}
|
|
|
|
|
2021-09-05 01:07:40 +00:00
|
|
|
// 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))
|
|
|
|
|
2022-01-14 03:55:25 +00:00
|
|
|
results.MatchingNodes.PushBack(node)
|
2021-09-05 01:07:40 +00:00
|
|
|
}
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|
2022-01-14 03:55:25 +00:00
|
|
|
log.Debug("and lets print it out")
|
|
|
|
log.Debug("all together: %v", results.ToString())
|
|
|
|
return results, nil
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|