Skip to content

Commit d2d6af4

Browse files
committed
Add meta information to query object
1 parent 134a99d commit d2d6af4

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

soql/parser/parser.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package parser
33
import (
44
"errors"
55
"strconv"
6+
"time"
67

78
"github.com/shellyln/go-open-soql-parser/soql/parser/core"
89
"github.com/shellyln/go-open-soql-parser/soql/parser/postprocess"
@@ -41,6 +42,12 @@ func Parse(s string) (*types.SoqlQuery, error) {
4142

4243
q := out.AstStack[0].Value.(types.SoqlQuery)
4344

45+
q.Meta = &types.SoqlQueryMeta{
46+
Version: "0.9",
47+
Date: time.Now().UTC(),
48+
Source: s,
49+
}
50+
4451
if err := postprocess.Normalize(&q); err != nil {
4552
return nil, err
4653
}

soql/parser/postprocess/normalize.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,13 @@ func Normalize(q *SoqlQuery) error {
372372
columnIdMap: make(map[string]int),
373373
colIndexMap: map[string]int{},
374374
}
375-
return ctx.normalizeQuery(soqlQueryPlace_Primary, q, nil)
375+
376+
if err := ctx.normalizeQuery(soqlQueryPlace_Primary, q, nil); err != nil {
377+
return err
378+
}
379+
380+
q.Meta.NextColumnId = ctx.columnId
381+
q.Meta.NextViewId = ctx.viewId
382+
383+
return nil
376384
}

soql/parser/types/marshaller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ func (t *SoqlFieldInfo) UnmarshalJSON(b []byte) error {
3434
t.Aggregated = t2.Aggregated
3535
t.Hints = t2.Hints
3636
t.ColumnId = t2.ColumnId
37-
t.ViewId = t2.ViewId
3837
t.ColIndex = t2.ColIndex
38+
t.ViewId = t2.ViewId
39+
t.Key = t2.Key
3940

4041
if v, err := unmarshalSoqlFieldInfoValue(t2.Value, t2.Type); err != nil {
4142
return err

soql/parser/types/types.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type SoqlFieldInfo struct {
9090
ColumnId int `json:"columnId,omitempty"` // (internal use) for all; 1-based; If 0, it is not set.; Unique column Id across all main and sub queries
9191
ColIndex int `json:"colIndex"` // Column index in the object
9292
ViewId int `json:"viewId,omitempty"` // TODO: (internal use) for SubQuery and Function; 1-based; If 0, it is not set.
93-
Key string `json:"-"` // (internal use) Base64-encoded, dot-delimited Name field value
93+
Key string `json:"key,omitempty"` // (internal use) Base64-encoded, dot-delimited Name field value
9494
}
9595

9696
type soqlFieldInfo_unmarshal struct {
@@ -106,6 +106,7 @@ type soqlFieldInfo_unmarshal struct {
106106
ColumnId int `json:"columnId,omitempty"`
107107
ColIndex int `json:"colIndex"`
108108
ViewId int `json:"viewId,omitempty"`
109+
Key string `json:"key,omitempty"`
109110
}
110111

111112
type SoqlListItem struct {
@@ -133,9 +134,9 @@ type SoqlObjectInfo struct {
133134
HasConditions bool `json:"hasConditions,omitempty"` // Query has conditions originally. If false and this object is on the right side, prevent performing an inner join.
134135
InnerJoin bool `json:"innerJoin,omitempty"` // When this object is on the left side, an inner join is performed.
135136
Hints []SoqlQueryHint `json:"hints,omitempty"` // TODO: hints
136-
PerObjectQuery *SoqlQuery `json:"-"` // A query that extracts only the filter and sort conditions and fields related to this object. A simple query, not including function calls, etc.
137+
PerObjectQuery *SoqlQuery `json:"perObjectQuery"` // A query that extracts only the filter and sort conditions and fields related to this object. A simple query, not including function calls, etc.
137138
ViewId int `json:"viewId,omitempty"` // TODO: (internal use) for SubQuery and Function; 1-based; If 0, it is not set.
138-
Key string `json:"-"` // (internal use) Base64-encoded, dot-delimited Name field value
139+
Key string `json:"key,omitempty"` // (internal use) Base64-encoded, dot-delimited Name field value
139140
}
140141

141142
type SoqlConditionOpcode int
@@ -240,19 +241,28 @@ type SoqlForClause struct {
240241
UpdateViewstat bool `json:"updateViewstat,omitempty"` // for update viewstat (set with Update)
241242
}
242243

244+
type SoqlQueryMeta struct {
245+
Version string `json:"version,omitempty"`
246+
Date time.Time `json:"date,omitempty"`
247+
Source string `json:"source,omitempty"`
248+
NextColumnId int `json:"nextColumnId,omitempty"`
249+
NextViewId int `json:"nextViewId,omitempty"`
250+
}
251+
243252
type SoqlQuery struct {
244-
Fields []SoqlFieldInfo `json:"fields,omitempty"` // Select clause fields; possibly null
245-
From []SoqlObjectInfo `json:"from,omitempty"` // From clause objects; has at least one element
246-
Where []SoqlCondition `json:"where,omitempty"` // Where clause conditions; possibly null; Not used in the execution planning phase.
247-
GroupBy []SoqlFieldInfo `json:"groupBy,omitempty"` // Group by clause fields; possibly null; Not used for "PerObjectQuery"
248-
Having []SoqlCondition `json:"having,omitempty"` // Having clause conditions; possibly null; Not used for "PerObjectQuery"
249-
OrderBy []SoqlOrderByInfo `json:"orderBy,omitempty"` // Order by clause fields; possibly null
250-
OffsetAndLimit SoqlOffsetAndLimitClause `json:"offsetAndLimit,omitempty"` // Offset and limit clause
251-
For SoqlForClause `json:"for,omitempty"` // For clause
252-
Parent *SoqlQuery `json:"-"` // Pointer to parent query; Not used for "PerObjectQuery"
253-
IsAggregation bool `json:"isAggregation,omitempty"` // It is an aggregation result or not; Not used for "PerObjectQuery"
254-
IsCorelated bool `json:"isCorelated,omitempty"` // TODO:
255-
PostProcessWhere []SoqlCondition `json:"-"` // Post-processing conditions (Conditions to apply after being filtered in the query for each object)
253+
Fields []SoqlFieldInfo `json:"fields,omitempty"` // Select clause fields; possibly null
254+
From []SoqlObjectInfo `json:"from,omitempty"` // From clause objects; has at least one element
255+
Where []SoqlCondition `json:"where,omitempty"` // Where clause conditions; possibly null; Not used in the execution planning phase.
256+
GroupBy []SoqlFieldInfo `json:"groupBy,omitempty"` // Group by clause fields; possibly null; Not used for "PerObjectQuery"
257+
Having []SoqlCondition `json:"having,omitempty"` // Having clause conditions; possibly null; Not used for "PerObjectQuery"
258+
OrderBy []SoqlOrderByInfo `json:"orderBy,omitempty"` // Order by clause fields; possibly null
259+
OffsetAndLimit SoqlOffsetAndLimitClause `json:"offsetAndLimit,omitempty"` // Offset and limit clause
260+
For SoqlForClause `json:"for,omitempty"` // For clause
261+
Parent *SoqlQuery `json:"-"` // Pointer to parent query; Not used for "PerObjectQuery"
262+
IsAggregation bool `json:"isAggregation,omitempty"` // It is an aggregation result or not; Not used for "PerObjectQuery"
263+
IsCorelated bool `json:"isCorelated,omitempty"` // TODO:
264+
PostProcessWhere []SoqlCondition `json:"postProcessWhere,omitempty"` // Post-processing conditions (Conditions to apply after being filtered in the query for each object)
265+
Meta *SoqlQueryMeta `json:"meta,omitempty"`
256266

257267
// ParameterizedValues map[string]struct{} `json:"-"` // TODO:
258268
// DateTimeLiterals map[string]struct{} `json:"-"` // TODO:

0 commit comments

Comments
 (0)