This commit is contained in:
Mike Farah 2022-01-14 14:55:25 +11:00
parent 2d7c63e4e4
commit 84ddf1862f
2 changed files with 20 additions and 4 deletions

View File

@ -1,5 +1,7 @@
package yqlib
import "container/list"
func unionOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debug("unionOperator")
log.Debug("context: %v", NodesToString(context.MatchingNodes))
@ -18,19 +20,25 @@ func unionOperator(d *dataTreeNavigator, context Context, expressionNode *Expres
log.Debug("lhs: %v", lhs.ToString())
log.Debug("rhs: %v", rhs.ToString())
results := lhs.ChildContext(list.New())
for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() {
node := el.Value.(*CandidateNode)
results.MatchingNodes.PushBack(node)
}
// 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)
results.MatchingNodes.PushBack(node)
}
}
log.Debug("all together: %v", lhs.ToString())
return lhs, nil
log.Debug("and lets print it out")
log.Debug("all together: %v", results.ToString())
return results, nil
}

View File

@ -13,6 +13,14 @@ var unionOperatorScenarios = []expressionScenario{
"D0, P[], (doc)::{}\n",
},
},
{
skipDoc: true,
description: "clone test",
expression: `"abc" as $a | [$a, "cat"]`,
expected: []string{
"D0, P[], (!!seq)::- abc\n- cat\n",
},
},
{
skipDoc: true,
expression: `(.foo = "bar"), (.toe = "jam")`,