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)
|
2022-02-07 00:55:55 +00:00
|
|
|
rhs, err := d.GetMatchingNodes(context.SingleReadonlyChildContext(candidate), 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
|
|
|
}
|
|
|
|
|
2021-10-07 04:04:36 +00:00
|
|
|
// find any truthy node
|
|
|
|
var errDecoding error
|
|
|
|
includeResult := false
|
2020-10-17 11:10:47 +00:00
|
|
|
|
2021-10-07 04:04:36 +00:00
|
|
|
for resultEl := rhs.MatchingNodes.Front(); resultEl != nil; resultEl = resultEl.Next() {
|
|
|
|
result := resultEl.Value.(*CandidateNode)
|
2023-04-09 01:14:51 +00:00
|
|
|
includeResult, errDecoding = isTruthyNode(result)
|
2021-05-16 02:16:10 +00:00
|
|
|
log.Debugf("isTruthy %v", includeResult)
|
2020-10-17 11:10:47 +00:00
|
|
|
if errDecoding != nil {
|
2021-02-02 07:17:59 +00:00
|
|
|
return Context{}, errDecoding
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|
|
|
|
if includeResult {
|
2021-10-07 04:04:36 +00:00
|
|
|
break
|
2020-10-17 11:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-07 04:04:36 +00:00
|
|
|
|
|
|
|
if includeResult {
|
|
|
|
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
|
|
|
}
|