mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 03:45:37 +00:00
wip
This commit is contained in:
parent
c63801a8a5
commit
76bd1896e9
@ -15,6 +15,9 @@ type CandidateNode struct {
|
|||||||
Document uint // the document index of this node
|
Document uint // the document index of this node
|
||||||
Filename string
|
Filename string
|
||||||
FileIndex int
|
FileIndex int
|
||||||
|
// when performing op against all nodes given, this will treat all the nodes as one
|
||||||
|
// (e.g. top level cross document merge). This property does not propegate to child nodes.
|
||||||
|
EvaluateTogether bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *CandidateNode) GetKey() string {
|
func (n *CandidateNode) GetKey() string {
|
||||||
|
@ -10,12 +10,8 @@ import (
|
|||||||
|
|
||||||
type crossFunctionCalculation func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error)
|
type crossFunctionCalculation func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error)
|
||||||
|
|
||||||
func crossFunction(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode, calculation crossFunctionCalculation) (*list.List, error) {
|
func doCrossFunc(d *dataTreeNavigator, contextList *list.List, expressionNode *ExpressionNode, calculation crossFunctionCalculation) (*list.List, error) {
|
||||||
|
|
||||||
var results = list.New()
|
var results = list.New()
|
||||||
for matchEl := matchingNodes.Front(); matchEl != nil; matchEl = matchEl.Next() {
|
|
||||||
contextList := nodeToMap(matchEl.Value.(*CandidateNode))
|
|
||||||
|
|
||||||
lhs, err := d.GetMatchingNodes(contextList, expressionNode.Lhs)
|
lhs, err := d.GetMatchingNodes(contextList, expressionNode.Lhs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -42,6 +38,21 @@ func crossFunction(d *dataTreeNavigator, matchingNodes *list.List, expressionNod
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func crossFunction(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode, calculation crossFunctionCalculation) (*list.List, error) {
|
||||||
|
var results = list.New()
|
||||||
|
for matchEl := matchingNodes.Front(); matchEl != nil; matchEl = matchEl.Next() {
|
||||||
|
contextList := nodeToMap(matchEl.Value.(*CandidateNode))
|
||||||
|
|
||||||
|
innerResults, err := doCrossFunc(d, contextList, expressionNode, calculation)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
results.PushBackList(innerResults)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ import (
|
|||||||
// d0a d1a d0b d1b
|
// d0a d1a d0b d1b
|
||||||
// run it for (d0a d1a) x (d0b d1b) - noting that we dont do (d0a x d1a) nor (d0b d1b)
|
// run it for (d0a d1a) x (d0b d1b) - noting that we dont do (d0a x d1a) nor (d0b d1b)
|
||||||
// I think this will work for eval-all correctly then..
|
// I think this will work for eval-all correctly then..
|
||||||
|
|
||||||
|
//alternative, like jq, eval-all puts all docs in an single array.
|
||||||
var multiplyOperatorScenarios = []expressionScenario{
|
var multiplyOperatorScenarios = []expressionScenario{
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
@ -25,7 +27,7 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
document: `a: {also: [1]}`,
|
document: `a: {also: [1]}`,
|
||||||
document2: `b: {also: me}`,
|
document2: `b: {also: me}`,
|
||||||
expression: `. * {"a" : .b}`,
|
expression: `.a * .b`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{a: {also: me}, b: {also: me}}\n",
|
"D0, P[], (!!map)::{a: {also: me}, b: {also: me}}\n",
|
||||||
},
|
},
|
||||||
|
@ -40,6 +40,7 @@ func readDocuments(reader io.Reader, filename string, fileIndex int) (*list.List
|
|||||||
Filename: filename,
|
Filename: filename,
|
||||||
Node: &dataBucket,
|
Node: &dataBucket,
|
||||||
FileIndex: fileIndex,
|
FileIndex: fileIndex,
|
||||||
|
EvaluateTogether: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
inputList.PushBack(candidateNode)
|
inputList.PushBack(candidateNode)
|
||||||
|
Loading…
Reference in New Issue
Block a user