Skip to content

Commit 0d80b14

Browse files
committed
Add view graph to meta info
1 parent 2e20293 commit 0d80b14

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

soql/parser/postprocess/normalize.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type normalizeQueryContext struct {
1717
colIndexMap map[string]int
1818
headObjDepthOffset int
1919
maxDepth int
20+
viewGraph map[int]SoqlGraphLeaf
2021
}
2122

2223
func (ctx *normalizeQueryContext) normalizeQuery(
@@ -257,12 +258,18 @@ func (ctx *normalizeQueryContext) normalizeQuery(
257258
if ctx.maxDepth < objDepth {
258259
ctx.maxDepth = objDepth
259260
}
261+
260262
if nameLen > 1 {
261263
parentKey := nameutil.MakeDottedKeyIgnoreCase(q.From[i].Name, nameLen-1)
262264
if parentViewId, ok := ctx.viewIdMap[parentKey]; ok {
263265
q.From[i].ParentViewId = parentViewId
264266
}
265267
}
268+
269+
ctx.viewGraph[q.From[i].ViewId] = SoqlGraphLeaf{
270+
ParentViewId: q.From[i].ParentViewId,
271+
Object: &q.From[i],
272+
}
266273
}
267274

268275
// TODO: * check object graph when aggregation(group by)
@@ -390,6 +397,7 @@ func Normalize(q *SoqlQuery) error {
390397
colIndexMap: map[string]int{},
391398
headObjDepthOffset: 0,
392399
maxDepth: 0,
400+
viewGraph: make(map[int]SoqlGraphLeaf),
393401
}
394402

395403
if err := ctx.normalizeQuery(soqlQueryPlace_Primary, q, nil); err != nil {
@@ -399,6 +407,7 @@ func Normalize(q *SoqlQuery) error {
399407
q.Meta.NextColumnId = ctx.columnId
400408
q.Meta.NextViewId = ctx.viewId
401409
q.Meta.MaxDepth = ctx.maxDepth
410+
q.Meta.ViewGraph = ctx.viewGraph
402411

403412
return nil
404413
}

soql/parser/types/types.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,19 @@ type SoqlForClause struct {
239239
UpdateViewstat bool `json:"updateViewstat,omitempty"` // for update viewstat (set with Update)
240240
}
241241

242+
type SoqlGraphLeaf struct {
243+
ParentViewId int `json:"parentViewId"`
244+
Object *SoqlObjectInfo `json:"-"`
245+
}
246+
242247
type SoqlQueryMeta struct {
243-
Version string `json:"version,omitempty"` // format version
244-
Date time.Time `json:"date,omitempty"` // compiled datetime
245-
Source string `json:"source,omitempty"` // source
246-
MaxDepth int `json:"maxDepth,omitempty"` // max depth of object graph
247-
NextColumnId int `json:"nextColumnId,omitempty"` // next column id (a number of columns)
248-
NextViewId int `json:"nextViewId,omitempty"` // next view id (a number of objects)
248+
Version string `json:"version,omitempty"` // format version
249+
Date time.Time `json:"date,omitempty"` // compiled datetime
250+
Source string `json:"source,omitempty"` // source
251+
MaxDepth int `json:"maxDepth,omitempty"` // max depth of object graph
252+
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)
254+
ViewGraph map[int]SoqlGraphLeaf `json:"viewGraph,omitempty"` //
249255
}
250256

251257
type SoqlQuery struct {

0 commit comments

Comments
 (0)