Skip to content

Commit ec34ea8

Browse files
committed
Add used functions, parameters, datetimeLiterals to meta info
1 parent 42ba1cb commit ec34ea8

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

soql/parser/postprocess/normalize.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type normalizeQueryContext struct {
2121
maxViewDepth int
2222
queryGraph map[int]SoqlQueryGraphLeaf
2323
viewGraph map[int]SoqlViewGraphLeaf
24+
functions map[string]struct{}
25+
parameters map[string]struct{}
26+
dateTimeLiterals map[string]struct{}
2427
}
2528

2629
func (ctx *normalizeQueryContext) normalizeQuery(
@@ -328,8 +331,6 @@ func (ctx *normalizeQueryContext) normalizeQuery(
328331
}
329332
}
330333

331-
// TODO: Associate with schema.
332-
333334
if err := ctx.buildPerObjectInfo(q); err != nil {
334335
return err
335336
}
@@ -354,6 +355,13 @@ func (ctx *normalizeQueryContext) normalizeQuery(
354355
}
355356
}
356357

358+
if q.OffsetAndLimit.OffsetParamName != "" {
359+
ctx.parameters[q.OffsetAndLimit.OffsetParamName] = struct{}{}
360+
}
361+
if q.OffsetAndLimit.LimitParamName != "" {
362+
ctx.parameters[q.OffsetAndLimit.LimitParamName] = struct{}{}
363+
}
364+
357365
savedViewIdMap := ctx.viewIdMap
358366
savedColumnIdMap := ctx.columnIdMap
359367
savedColIndexMap := ctx.colIndexMap
@@ -426,6 +434,9 @@ func Normalize(q *SoqlQuery) error {
426434
maxViewDepth: 0,
427435
queryGraph: make(map[int]SoqlQueryGraphLeaf),
428436
viewGraph: make(map[int]SoqlViewGraphLeaf),
437+
functions: make(map[string]struct{}),
438+
parameters: make(map[string]struct{}),
439+
dateTimeLiterals: make(map[string]struct{}),
429440
}
430441

431442
if err := ctx.normalizeQuery(soqlQueryPlace_Primary, q, nil, 1, nil); err != nil {
@@ -439,6 +450,9 @@ func Normalize(q *SoqlQuery) error {
439450
q.Meta.MaxViewDepth = ctx.maxViewDepth
440451
q.Meta.QueryGraph = ctx.queryGraph
441452
q.Meta.ViewGraph = ctx.viewGraph
453+
q.Meta.Functions = ctx.functions
454+
q.Meta.Parameters = ctx.parameters
455+
q.Meta.DateTimeLiterals = ctx.dateTimeLiterals
442456

443457
return nil
444458
}

soql/parser/postprocess/normalize1.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func (ctx *normalizeQueryContext) normalizeFieldName(
166166
if len(field.Name) == 1 {
167167
funcName = strings.ToLower(field.Name[0])
168168
}
169+
ctx.functions[strings.ToLower(funcName)] = struct{}{}
169170

170171
if conf.isFunctionParameter {
171172
// Check function names not allowed in nested
@@ -318,6 +319,10 @@ func (ctx *normalizeQueryContext) normalizeFieldName(
318319
"The fields() is not allowed in conditional clause or function parameter: " +
319320
strings.Join(field.Name, "."))
320321
}
322+
case SoqlFieldInfo_ParameterizedValue:
323+
ctx.parameters[strings.ToLower(field.Name[0])] = struct{}{}
324+
case SoqlFieldInfo_DateTimeLiteralName:
325+
ctx.dateTimeLiterals[strings.ToLower(field.Name[0])] = struct{}{}
321326
}
322327

323328
return nil

soql/parser/types/types.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,20 @@ type SoqlQueryGraphLeaf struct {
256256
}
257257

258258
type SoqlQueryMeta struct {
259-
Version string `json:"version,omitempty"` // format version
260-
Date time.Time `json:"date,omitempty"` // compiled datetime
261-
ElapsedTime time.Duration `json:"elapsedTime,omitempty"` // time taken to compile
262-
Source string `json:"source,omitempty"` // source
263-
MaxQueryDepth int `json:"maxQueryDepth,omitempty"` // max depth of query graph
264-
MaxViewDepth int `json:"maxViewDepth,omitempty"` // max depth of object graph
265-
NextQueryId int `json:"nextQueryId,omitempty"` // next query id (a number of queries)
266-
NextViewId int `json:"nextViewId,omitempty"` // next view id (a number of views)
267-
NextColumnId int `json:"nextColumnId,omitempty"` // next column id (a number of columns)
268-
QueryGraph map[int]SoqlQueryGraphLeaf `json:"queryGraph,omitempty"` // query graph (child -> parent)
269-
ViewGraph map[int]SoqlViewGraphLeaf `json:"viewGraph,omitempty"` // object graph (child -> parent)
270-
// TODO: Parameters, DateTimeLiterals
259+
Version string `json:"version,omitempty"` // format version
260+
Date time.Time `json:"date,omitempty"` // compiled datetime
261+
ElapsedTime time.Duration `json:"elapsedTime,omitempty"` // time taken to compile
262+
Source string `json:"source,omitempty"` // source
263+
MaxQueryDepth int `json:"maxQueryDepth,omitempty"` // max depth of query graph
264+
MaxViewDepth int `json:"maxViewDepth,omitempty"` // max depth of object graph
265+
NextQueryId int `json:"nextQueryId,omitempty"` // next query id (a number of queries)
266+
NextViewId int `json:"nextViewId,omitempty"` // next view id (a number of views)
267+
NextColumnId int `json:"nextColumnId,omitempty"` // next column id (a number of columns)
268+
QueryGraph map[int]SoqlQueryGraphLeaf `json:"queryGraph,omitempty"` // query graph (child -> parent)
269+
ViewGraph map[int]SoqlViewGraphLeaf `json:"viewGraph,omitempty"` // object graph (child -> parent)
270+
Functions map[string]struct{} `json:"functions,omitempty"` // functions
271+
Parameters map[string]struct{} `json:"parameters,omitempty"` // parameters
272+
DateTimeLiterals map[string]struct{} `json:"dateTimeLiterals,omitempty"` // datetime literals
271273
}
272274

273275
type SoqlQuery struct {

0 commit comments

Comments
 (0)