mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	cross function fix wip
This commit is contained in:
		
							parent
							
								
									5fb88627ca
								
							
						
					
					
						commit
						af3a9ae846
					
				| @ -5,6 +5,15 @@ import ( | ||||
| ) | ||||
| 
 | ||||
| var addOperatorScenarios = []expressionScenario{ | ||||
| 	{ | ||||
| 		skipDoc:    true, | ||||
| 		document:   `[{a: foo, b: bar}, {a: 1, b: 2}]`, | ||||
| 		expression: ".[] | .a + .b", | ||||
| 		expected: []string{ | ||||
| 			"D0, P[0 a], (!!str)::foobar\n", | ||||
| 			"D0, P[1 a], (!!int)::3\n", | ||||
| 		}, | ||||
| 	}, | ||||
| 	{ | ||||
| 		description: "Concatenate and assign arrays", | ||||
| 		document:    `{a: {val: thing, b: [cat,dog]}}`, | ||||
|  | ||||
| @ -11,20 +11,22 @@ import ( | ||||
| 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) { | ||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||
| 
 | ||||
| 	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) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		log.Debugf("crossFunction LHS len: %v", lhs.Len()) | ||||
| 
 | ||||
| 	rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||
| 		rhs, err := d.GetMatchingNodes(contextList, expressionNode.Rhs) | ||||
| 
 | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	log.Debugf("crossFunction RHS len: %v", rhs.Len()) | ||||
| 
 | ||||
| 	var results = list.New() | ||||
| 
 | ||||
| 		for el := lhs.Front(); el != nil; el = el.Next() { | ||||
| 			lhsCandidate := el.Value.(*CandidateNode) | ||||
| @ -40,6 +42,9 @@ func crossFunction(d *dataTreeNavigator, matchingNodes *list.List, expressionNod | ||||
| 			} | ||||
| 
 | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	return results, nil | ||||
| } | ||||
| 
 | ||||
| @ -69,7 +74,8 @@ func multiply(preferences multiplyPreferences) func(d *dataTreeNavigator, lhs *C | ||||
| 				return nil, err | ||||
| 			} | ||||
| 			return mergeObjects(d, newThing, rhs, preferences) | ||||
| 
 | ||||
| 		} else if lhs.Node.Tag == "!!int" && rhs.Node.Tag == "!!int" { | ||||
| 			return lhs.CreateChild(nil, &yaml.Node{Kind: yaml.ScalarNode, Tag: "!!str", Value: "12"}), nil | ||||
| 		} | ||||
| 		return nil, fmt.Errorf("Cannot multiply %v with %v", lhs.Node.Tag, rhs.Node.Tag) | ||||
| 	} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user