2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-17 11:10:47 +00:00
|
|
|
|
|
|
|
import (
|
2020-10-21 01:54:58 +00:00
|
|
|
"container/list"
|
2020-10-17 11:10:47 +00:00
|
|
|
)
|
|
|
|
|
2021-02-02 07:17:59 +00:00
|
|
|
func selectOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
2020-10-17 11:10:47 +00:00
|
|
|
|
|
|
|
log.Debugf("-- selectOperation")
|
2020-10-21 01:54:58 +00:00
|
|
|
var results = list.New()
|
2020-10-17 11:10:47 +00:00
|
|
|
|
2021-02-02 07:17:59 +00:00
|
|
|
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
|
2020-10-17 11:10:47 +00:00
|
|
|
candidate := el.Value.(*CandidateNode)
|
2021-02-03 00:54:10 +00:00
|
|
|
childContext := context.SingleChildContext(candidate)
|
|
|
|
childContext.DontAutoCreate = true
|
|
|
|
rhs, err := d.GetMatchingNodes(childContext, expressionNode.Rhs)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// grab the first value
|
2021-02-02 07:17:59 +00:00
|
|
|
first := rhs.MatchingNodes.Front()
|
2020-10-17 11:10:47 +00:00
|
|
|
|
|
|
|
if first != nil {
|
|
|
|
result := first.Value.(*CandidateNode)
|
|
|
|
includeResult, errDecoding := isTruthy(result)
|
|
|
|
if errDecoding != nil {
|
2021-02-02 07:17:59 +00:00
|
|
|
return Context{}, errDecoding
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if includeResult {
|
2020-10-21 01:54:58 +00:00
|
|
|
results.PushBack(candidate)
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-02 07:17:59 +00:00
|
|
|
return context.ChildContext(results), nil
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|