Skip to content

Commit 278e49c

Browse files
committed
[FIX] Fix the flag that view is inner join or not. [FIX] Fix the non-result flag
1 parent 053e6ea commit 278e49c

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

soql/parser/parser_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func TestParse2(t *testing.T) {
177177
, CONCAT(TRIM(acc.Name), '/', TRIM(con.Name), 123.45, 0xacc0) cname
178178
, FLAT(acc.Name)
179179
, (SELECT Id FROM con.Departments where uuu=con.Zzz and vvv=con.Id) qwerty
180-
, (select Id from r3.lkjh)
180+
, (select Id from r3.lkjh where name='www')
181181
FROM
182182
Contact con
183183
, con.Account acc
@@ -189,7 +189,7 @@ func TestParse2(t *testing.T) {
189189
and
190190
acc.Id in ('a', 'b', 'c', null)
191191
and
192-
r3.Name in (select x,Id,Name from Contact)
192+
r3.Name in (select x,Id,Name,(select w from ghjksfd) from Contact)
193193
and
194194
Name > 0001-01-02
195195
and
@@ -200,6 +200,8 @@ func TestParse2(t *testing.T) {
200200
con.Name = acc.Name
201201
and
202202
LEN(con.Name) > 0
203+
and
204+
foo__r.bar__r.zzz = 1
203205
ORDER BY
204206
acc.Name desc nulls last
205207
--, acc.Id desc nulls last

soql/parser/postprocess/normalize.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func (ctx *normalizeQueryContext) normalizeQuery(
297297
Depth: objDepth,
298298
QueryDepth: queryDepth,
299299
Many: qPlace == soqlQueryPlace_Select && i == 0,
300-
InnerJoin: q.From[i].InnerJoin,
300+
InnerJoin: false, // set later
301301
NonResult: qPlace == soqlQueryPlace_ConditionalOperand,
302302
Object: &q.From[i],
303303
Query: q,
@@ -335,6 +335,12 @@ func (ctx *normalizeQueryContext) normalizeQuery(
335335
return err
336336
}
337337

338+
for i := 0; i < len(q.From); i++ {
339+
leaf := ctx.viewGraph[q.From[i].ViewId]
340+
leaf.InnerJoin = q.From[i].InnerJoin
341+
ctx.viewGraph[q.From[i].ViewId] = leaf
342+
}
343+
338344
for i := 0; i < len(q.Fields); i++ {
339345
field := q.Fields[i]
340346

@@ -453,6 +459,37 @@ func Normalize(q *SoqlQuery) error {
453459
return err
454460
}
455461

462+
// Propagate InnerJoin and NonResult of ctx.viewGraph
463+
for k := range ctx.viewGraph {
464+
leaf := ctx.viewGraph[k]
465+
if leaf.InnerJoin {
466+
next := leaf.ParentViewId
467+
for next != 0 {
468+
l2 := ctx.viewGraph[next]
469+
if l2.Depth == 1 || l2.Many || l2.QueryId != leaf.QueryId {
470+
break
471+
}
472+
l2.InnerJoin = true
473+
ctx.viewGraph[next] = l2
474+
next = l2.ParentViewId
475+
}
476+
}
477+
if leaf.NonResult {
478+
var applyNonResult func(next int)
479+
applyNonResult = func(next int) {
480+
for w := range ctx.viewGraph {
481+
l2 := ctx.viewGraph[w]
482+
if l2.ParentViewId == next {
483+
l2.NonResult = true
484+
ctx.viewGraph[w] = l2
485+
applyNonResult(w)
486+
}
487+
}
488+
}
489+
applyNonResult(k)
490+
}
491+
}
492+
456493
q.Meta.NextQueryId = ctx.queryId
457494
q.Meta.NextViewId = ctx.viewId
458495
q.Meta.NextColumnId = ctx.columnId

soql/parser/postprocess/normalizeperobj.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ CHECK_FIELDS:
8787
}
8888
}
8989
}
90-
if !hasConditionsOriginally {
91-
// TODO: More conditions?
92-
innerJoined = true
93-
}
9490

9591
for i := 0; i < len(conditions); i++ {
9692
cond := conditions[i]
@@ -362,6 +358,7 @@ func (ctx *normalizeQueryContext) buildPerObjectInfo(q *SoqlQuery) error {
362358

363359
perObjQuery.For = q.For
364360
}
361+
q.From[0].InnerJoin = false
365362

366363
if err := makePostProcessWhereClause(q); err != nil {
367364
return err

0 commit comments

Comments
 (0)