Skip to content

Commit b7f1e2f

Browse files
committed
Add Depth, QueryDepth, Query to QueryGraph. Add query id to query object.
1 parent 0d80b14 commit b7f1e2f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

soql/parser/postprocess/normalize.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type normalizeQueryContext struct {
13+
queryId int
1314
viewId int
1415
viewIdMap map[string]int
1516
columnId int
@@ -23,6 +24,9 @@ type normalizeQueryContext struct {
2324
func (ctx *normalizeQueryContext) normalizeQuery(
2425
qPlace soqlQueryPlace, q *SoqlQuery, objNameMap map[string][]string) error {
2526

27+
q.QueryId = ctx.queryId
28+
ctx.queryId++
29+
2630
var primaryObjectName []string // TODO: name is not good? it is primary or parent object
2731

2832
if qPlace == soqlQueryPlace_Primary || qPlace == soqlQueryPlace_ConditionalOperand {
@@ -268,7 +272,10 @@ func (ctx *normalizeQueryContext) normalizeQuery(
268272

269273
ctx.viewGraph[q.From[i].ViewId] = SoqlGraphLeaf{
270274
ParentViewId: q.From[i].ParentViewId,
275+
Depth: objDepth,
276+
QueryDepth: ctx.headObjDepthOffset + 1,
271277
Object: &q.From[i],
278+
Query: q,
272279
}
273280
}
274281

@@ -390,6 +397,7 @@ func (ctx *normalizeQueryContext) normalizeQuery(
390397

391398
func Normalize(q *SoqlQuery) error {
392399
ctx := normalizeQueryContext{
400+
queryId: 1,
393401
viewId: 1,
394402
viewIdMap: make(map[string]int),
395403
columnId: 1,
@@ -406,6 +414,7 @@ func Normalize(q *SoqlQuery) error {
406414

407415
q.Meta.NextColumnId = ctx.columnId
408416
q.Meta.NextViewId = ctx.viewId
417+
q.Meta.NextQueryId = ctx.queryId
409418
q.Meta.MaxDepth = ctx.maxDepth
410419
q.Meta.ViewGraph = ctx.viewGraph
411420

soql/parser/types/types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ type SoqlForClause struct {
241241

242242
type SoqlGraphLeaf struct {
243243
ParentViewId int `json:"parentViewId"`
244+
Depth int `json:"depth"`
245+
QueryDepth int `json:"queryDepth"`
244246
Object *SoqlObjectInfo `json:"-"`
247+
Query *SoqlQuery `json:"-"`
245248
}
246249

247250
type SoqlQueryMeta struct {
@@ -250,7 +253,8 @@ type SoqlQueryMeta struct {
250253
Source string `json:"source,omitempty"` // source
251254
MaxDepth int `json:"maxDepth,omitempty"` // max depth of object graph
252255
NextColumnId int `json:"nextColumnId,omitempty"` // next column id (a number of columns)
253-
NextViewId int `json:"nextViewId,omitempty"` // next view id (a number of objects)
256+
NextViewId int `json:"nextViewId,omitempty"` // next view id (a number of views)
257+
NextQueryId int `json:"nextQueryId,omitempty"` // next query id (a number of queries)
254258
ViewGraph map[int]SoqlGraphLeaf `json:"viewGraph,omitempty"` //
255259
}
256260

@@ -267,6 +271,7 @@ type SoqlQuery struct {
267271
IsAggregation bool `json:"isAggregation,omitempty"` // It is an aggregation result or not; Not used for "PerObjectQuery"
268272
IsCorelated bool `json:"isCorelated,omitempty"` // Co-related query if true
269273
PostProcessWhere []SoqlCondition `json:"postProcessWhere,omitempty"` // Post-processing conditions (Conditions to apply after being filtered in the query for each object)
274+
QueryId int `json:"queryId,omitempty"`
270275
Meta *SoqlQueryMeta `json:"meta,omitempty"`
271276

272277
// ParameterizedValues map[string]struct{} `json:"-"` // TODO:

0 commit comments

Comments
 (0)