mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-24 06:35:40 +00:00
Fixed handling of nulls with sort_by expressions #2164
This commit is contained in:
parent
f238f01856
commit
4af292f076
@ -69,6 +69,7 @@ func (a sortableNodeArray) Less(i, j int) bool {
|
|||||||
rhsContext := a[j].CompareContext
|
rhsContext := a[j].CompareContext
|
||||||
|
|
||||||
rhsEl := rhsContext.MatchingNodes.Front()
|
rhsEl := rhsContext.MatchingNodes.Front()
|
||||||
|
|
||||||
for lhsEl := lhsContext.MatchingNodes.Front(); lhsEl != nil && rhsEl != nil; lhsEl = lhsEl.Next() {
|
for lhsEl := lhsContext.MatchingNodes.Front(); lhsEl != nil && rhsEl != nil; lhsEl = lhsEl.Next() {
|
||||||
lhs := lhsEl.Value.(*CandidateNode)
|
lhs := lhsEl.Value.(*CandidateNode)
|
||||||
rhs := rhsEl.Value.(*CandidateNode)
|
rhs := rhsEl.Value.(*CandidateNode)
|
||||||
@ -83,7 +84,7 @@ func (a sortableNodeArray) Less(i, j int) bool {
|
|||||||
|
|
||||||
rhsEl = rhsEl.Next()
|
rhsEl = rhsEl.Next()
|
||||||
}
|
}
|
||||||
return false
|
return lhsContext.MatchingNodes.Len() < rhsContext.MatchingNodes.Len()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a sortableNodeArray) compare(lhs *CandidateNode, rhs *CandidateNode, dateTimeLayout string) int {
|
func (a sortableNodeArray) compare(lhs *CandidateNode, rhs *CandidateNode, dateTimeLayout string) int {
|
||||||
|
@ -21,6 +21,17 @@ var sortByOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[0], (!!map)::{a: banana}\n",
|
"D0, P[0], (!!map)::{a: banana}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Sort by with null",
|
||||||
|
skipDoc: true,
|
||||||
|
document: "[{a: banana},null,{a: apple}]",
|
||||||
|
expression: `sort_by(.a)[]`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[1], (!!null)::null\n",
|
||||||
|
"D0, P[2], (!!map)::{a: apple}\n",
|
||||||
|
"D0, P[0], (!!map)::{a: banana}\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Sort by multiple fields",
|
description: "Sort by multiple fields",
|
||||||
document: "[{a: dog},{a: cat, b: banana},{a: cat, b: apple}]",
|
document: "[{a: dog},{a: cat, b: banana},{a: cat, b: apple}]",
|
||||||
|
Loading…
Reference in New Issue
Block a user