1
1
package postprocess
2
2
3
3
import (
4
+ "errors"
5
+ "strings"
6
+
7
+ "github.com/shellyln/go-nameutil/nameutil"
4
8
. "github.com/shellyln/go-open-soql-parser/soql/parser/types"
5
9
)
6
10
7
- func (ctx * normalizeQueryContext ) applyColIndexToFields (q * SoqlQuery , fields []SoqlFieldInfo ) {
11
+ func (ctx * normalizeQueryContext ) applyColIndexToFields (q * SoqlQuery , fields []SoqlFieldInfo ) error {
8
12
for i := range fields {
9
13
switch fields [i ].Type {
10
14
case SoqlFieldInfo_Field :
@@ -13,16 +17,44 @@ func (ctx *normalizeQueryContext) applyColIndexToFields(q *SoqlQuery, fields []S
13
17
} else {
14
18
fields [i ].ColIndex = - 1
15
19
}
20
+
16
21
if len (fields [i ].Name ) <= len (q .From [0 ].Name ) {
17
22
q .IsCorelated = true
18
- // if fields[i].ColIndex == -1 {
19
- // // TODO:
20
- // }
23
+
24
+ if fields [i ].ColIndex == - 1 {
25
+ isSet := false
26
+
27
+ if q .Parent != nil {
28
+ ns := nameutil .GetNamespaceFromName (fields [i ].Name )
29
+ nsKey := nameutil .MakeDottedKeyIgnoreCase (ns , len (ns ))
30
+
31
+ for j := range q .Parent .From {
32
+ if q .Parent .From [j ].Key == nsKey {
33
+ idx := len (q .Parent .From [j ].PerObjectQuery .Fields )
34
+
35
+ ctx .colIndexMap [fields [i ].Key ] = idx
36
+ fields [i ].ColIndex = idx
37
+
38
+ q .Parent .Fields = append (q .Parent .Fields , fields [i ])
39
+ q .Parent .From [j ].PerObjectQuery .Fields = append (q .Parent .From [j ].PerObjectQuery .Fields , fields [i ])
40
+
41
+ isSet = true
42
+ break
43
+ }
44
+ }
45
+ }
46
+ if ! isSet {
47
+ return errors .New (
48
+ "An incorrect ancestor field of object referred to in the correlated subquery: " +
49
+ strings .Join (fields [i ].Name , "." ))
50
+ }
51
+ }
21
52
}
22
53
case SoqlFieldInfo_Function :
23
54
ctx .applyColIndexToFields (q , fields [i ].Parameters )
24
55
}
25
56
}
57
+ return nil
26
58
}
27
59
28
60
func (ctx * normalizeQueryContext ) applyColIndexToConditions (q * SoqlQuery , conditions []SoqlCondition ) {
0 commit comments