-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsyntax_basic_compare_query.go
66 lines (54 loc) · 1.54 KB
/
syntax_basic_compare_query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package jsonpath
type syntaxBasicCompareQuery struct {
leftParam *syntaxBasicCompareParameter
rightParam *syntaxBasicCompareParameter
comparator syntaxComparator
}
func (q *syntaxBasicCompareQuery) compute(
root interface{}, currentList []interface{}, container *bufferContainer) []interface{} {
leftValues := q.leftParam.compute(root, currentList, container)
q.comparator.typeCast(leftValues)
rightValues := q.rightParam.compute(root, currentList, container)
q.comparator.typeCast(rightValues)
var leftPartialFound bool
var rightPartialFound bool
for leftIndex := range leftValues {
if _, ok := leftValues[leftIndex].(struct{}); ok {
continue
}
leftPartialFound = true
for rightIndex := range rightValues {
if _, ok := rightValues[rightIndex].(struct{}); ok {
continue
}
rightPartialFound = true
if q.comparator.comparator(leftValues[leftIndex], rightValues[rightIndex]) {
if q.leftParam.isLiteral && q.rightParam.isLiteral {
return leftValues
}
continue
}
if !q.leftParam.isLiteral {
leftValues[leftIndex] = struct{}{}
break
} else if !q.rightParam.isLiteral {
rightValues[rightIndex] = struct{}{}
} else {
leftValues[0] = struct{}{}
return leftValues[:1]
}
}
if !rightPartialFound && !q.leftParam.isLiteral {
leftValues[leftIndex] = struct{}{}
}
}
if !leftPartialFound && !q.rightParam.isLiteral {
for rightIndex := range rightValues {
rightValues[rightIndex] = struct{}{}
}
}
if !q.leftParam.isLiteral {
return leftValues
}
return rightValues
}