Skip to content

Commit 5cd5642

Browse files
committed
Improve conditional subquery output
1 parent 104aa08 commit 5cd5642

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

soql/visualizer/visualizer.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,47 @@ func Visualize(q *types.SoqlQuery) string {
1616
qLeaf := q.Meta.QueryGraph[leaf.QueryId]
1717
if qLeaf.ParentQueryId != 0 {
1818
parentQLeaf := q.Meta.QueryGraph[qLeaf.ParentQueryId]
19-
parentName := parentQLeaf.Query.From[0].Name
19+
parentQuery := parentQLeaf.Query
20+
21+
parentName := parentQuery.From[0].Name
22+
parentColName := ""
2023
fields := leaf.Object.PerObjectQuery.Fields
2124

22-
colName := ""
25+
namesFound := false
26+
collectNames := func(conditions []types.SoqlCondition) {
27+
for i := range conditions {
28+
if conditions[i].Opcode == types.SoqlConditionOpcode_FieldInfo &&
29+
conditions[i].Value.Type == types.SoqlFieldInfo_SubQuery {
30+
31+
sq := conditions[i].Value.SubQuery
32+
if sq == leaf.Query {
33+
if i > 0 && conditions[i-1].Opcode == types.SoqlConditionOpcode_FieldInfo &&
34+
conditions[i-1].Value.Type == types.SoqlFieldInfo_Field {
35+
36+
nm := conditions[i-1].Value.Name
37+
parentNameLen := len(nm)
38+
if parentNameLen > 0 {
39+
parentName = nm[:parentNameLen-1]
40+
parentColName = nm[parentNameLen-1] + " "
41+
namesFound = true
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
49+
collectNames(parentQuery.PostProcessWhere)
50+
if !namesFound {
51+
collectNames(parentQuery.Having)
52+
}
53+
54+
subqColName := ""
2355
if len(fields) > 0 && len(fields[0].Name) > 0 {
24-
colName = fields[0].Name[len(fields[0].Name)-1]
56+
subqColName = fields[0].Name[len(fields[0].Name)-1]
2557
}
2658

27-
relations += fmt.Sprintf("%v ||..o{ %v: \"in %v\"\n", parentName[len(parentName)-1], leaf.Name, colName)
59+
relations += fmt.Sprintf("%v ||..o{ %v: \"%vin %v\"\n", parentName[len(parentName)-1], leaf.Name, parentColName, subqColName)
2860
}
2961
continue
3062
}

0 commit comments

Comments
 (0)