mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +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,38 +10,49 @@ 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()
|
||||||
|
lhs, err := d.GetMatchingNodes(contextList, expressionNode.Lhs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
log.Debugf("crossFunction LHS len: %v", lhs.Len())
|
||||||
|
|
||||||
|
rhs, err := d.GetMatchingNodes(contextList, expressionNode.Rhs)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for el := lhs.Front(); el != nil; el = el.Next() {
|
||||||
|
lhsCandidate := el.Value.(*CandidateNode)
|
||||||
|
|
||||||
|
for rightEl := rhs.Front(); rightEl != nil; rightEl = rightEl.Next() {
|
||||||
|
log.Debugf("Applying calc")
|
||||||
|
rhsCandidate := rightEl.Value.(*CandidateNode)
|
||||||
|
resultCandidate, err := calculation(d, lhsCandidate, rhsCandidate)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
results.PushBack(resultCandidate)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func crossFunction(d *dataTreeNavigator, matchingNodes *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() {
|
for matchEl := matchingNodes.Front(); matchEl != nil; matchEl = matchEl.Next() {
|
||||||
contextList := nodeToMap(matchEl.Value.(*CandidateNode))
|
contextList := nodeToMap(matchEl.Value.(*CandidateNode))
|
||||||
|
|
||||||
lhs, err := d.GetMatchingNodes(contextList, expressionNode.Lhs)
|
innerResults, err := doCrossFunc(d, contextList, expressionNode, calculation)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
log.Debugf("crossFunction LHS len: %v", lhs.Len())
|
|
||||||
|
|
||||||
rhs, err := d.GetMatchingNodes(contextList, expressionNode.Rhs)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for el := lhs.Front(); el != nil; el = el.Next() {
|
results.PushBackList(innerResults)
|
||||||
lhsCandidate := el.Value.(*CandidateNode)
|
|
||||||
|
|
||||||
for rightEl := rhs.Front(); rightEl != nil; rightEl = rightEl.Next() {
|
|
||||||
log.Debugf("Applying calc")
|
|
||||||
rhsCandidate := rightEl.Value.(*CandidateNode)
|
|
||||||
resultCandidate, err := calculation(d, lhsCandidate, rhsCandidate)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
results.PushBack(resultCandidate)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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",
|
||||||
},
|
},
|
||||||
|
@ -36,10 +36,11 @@ func readDocuments(reader io.Reader, filename string, fileIndex int) (*list.List
|
|||||||
return nil, errorReading
|
return nil, errorReading
|
||||||
}
|
}
|
||||||
candidateNode := &CandidateNode{
|
candidateNode := &CandidateNode{
|
||||||
Document: currentIndex,
|
Document: currentIndex,
|
||||||
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