yq/pkg/yqlib/operator_select.go

38 lines
763 B
Go
Raw Normal View History

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-01-12 23:18:53 +00:00
func selectOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, 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
for el := matchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
2021-01-12 23:18:53 +00:00
rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs)
2020-10-17 11:10:47 +00:00
if err != nil {
return nil, err
}
// grab the first value
first := rhs.Front()
if first != nil {
result := first.Value.(*CandidateNode)
includeResult, errDecoding := isTruthy(result)
if errDecoding != nil {
return nil, errDecoding
}
if includeResult {
2020-10-21 01:54:58 +00:00
results.PushBack(candidate)
2020-10-17 11:10:47 +00:00
}
}
}
return results, nil
}