Skip to content

Commit a274431

Browse files
authored
fix(core): Fix regression in computing cond variables (#9126)
Fixes: #9125
1 parent cc4d474 commit a274431

File tree

5 files changed

+77
-13
lines changed

5 files changed

+77
-13
lines changed

graphql/e2e/schema/schema_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ import (
4242
)
4343

4444
var (
45-
groupOneHTTP = testutil.ContainerAddr("alpha1", 8080)
46-
groupTwoHTTP = testutil.ContainerAddr("alpha2", 8080)
47-
groupThreeHTTP = testutil.ContainerAddr("alpha3", 8080)
45+
groupOneHTTP = testutil.ContainerAddr0("alpha1", 8080)
46+
groupTwoHTTP = testutil.ContainerAddr0("alpha2", 8080)
47+
groupThreeHTTP = testutil.ContainerAddr0("alpha3", 8080)
4848
groupOnegRPC = testutil.SockAddr
4949

5050
groupOneGraphQLServer = "http://" + groupOneHTTP + "/graphql"

query/common_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,19 @@ tweet-c : string @index(fulltext) .
345345
tweet-d : string @index(trigram) .
346346
name2 : string @index(term) .
347347
age2 : int @index(int) .
348+
349+
DispatchBoard.column: uid @reverse .
350+
order: int .
351+
352+
type DispatchBoardColumn {
353+
name
354+
}
355+
356+
type DispatchBoardCard {
357+
DispatchBoard.column
358+
order
359+
}
360+
348361
`
349362

350363
func populateCluster(dc dgraphapi.Cluster) {
@@ -892,6 +905,16 @@ func populateCluster(dc dgraphapi.Cluster) {
892905
893906
<40> <name2> "Alice" .
894907
<41> <age2> "20" .
908+
909+
<1023> <dgraph.type> "DispatchBoardColumn" .
910+
<1024> <dgraph.type> "DispatchBoardColumn" .
911+
<1025> <dgraph.type> "DispatchBoardCard" .
912+
<1026> <dgraph.type> "DispatchBoardCard" .
913+
914+
<1025> <DispatchBoard.column> <1023> .
915+
<1025> <order> "0" .
916+
<1026> <DispatchBoard.column> <1023> .
917+
<1026> <order> "1" .
895918
`)
896919
x.Panic(err)
897920

query/query.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,13 +1185,6 @@ func (sg *SubGraph) transformVars(doneVars map[string]varValue, path []*SubGraph
11851185
mt.Const = val
11861186
continue
11871187
}
1188-
// TODO: Need to understand why certain aggregations map to uid = 0
1189-
// while others map to uid = MaxUint64
1190-
if val, ok := newMap[0]; ok && len(newMap) == 1 {
1191-
mt.Const = val
1192-
continue
1193-
}
1194-
11951188
mt.Val = newMap
11961189
}
11971190
return nil

query/query0_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,6 +3547,46 @@ func TestEqFilterWithoutIndex(t *testing.T) {
35473547

35483548
}
35493549

3550+
func TestCondCondition(t *testing.T) {
3551+
tests := []struct {
3552+
name string
3553+
query string
3554+
expected string
3555+
}{
3556+
{
3557+
`Test Cond`,
3558+
`{
3559+
var(func: uid(0x3ff)) {
3560+
columnUid as uid
3561+
~DispatchBoard.column { o as order }
3562+
cards as count(~DispatchBoard.column)
3563+
}
3564+
3565+
var() {
3566+
lastPosition as max(val(o))
3567+
cardCount as max(val(cards))
3568+
nextPosition as math(cond(cardCount==0, 0, lastPosition+1))
3569+
}
3570+
3571+
q(func: uid(columnUid)) {
3572+
val(lastPosition)
3573+
val(cardCount)
3574+
val(nextPosition)
3575+
uid
3576+
}
3577+
}`,
3578+
`{"data":{"q": [{"uid": "0x3ff"}] }}`,
3579+
},
3580+
}
3581+
3582+
for _, tc := range tests {
3583+
t.Run(tc.name, func(t *testing.T) {
3584+
result := processQueryNoErr(t, tc.query)
3585+
require.JSONEq(t, tc.expected, result)
3586+
})
3587+
}
3588+
}
3589+
35503590
func TestMatchingWithPagination(t *testing.T) {
35513591
tests := []struct {
35523592
name string

testutil/docker.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,22 @@ func AllContainers(prefix string) []types.Container {
208208
return out
209209
}
210210

211-
func ContainerAddr(name string, privatePort uint16) string {
211+
func ContainerAddrWithHost(name string, privatePort uint16, host string) string {
212212
c := getContainer(name)
213213
for _, p := range c.Ports {
214214
if p.PrivatePort == privatePort {
215-
return "localhost:" + strconv.Itoa(int(p.PublicPort))
215+
return host + ":" + strconv.Itoa(int(p.PublicPort))
216216
}
217217
}
218-
return "localhost:" + strconv.Itoa(int(privatePort))
218+
return host + ":" + strconv.Itoa(int(privatePort))
219+
}
220+
221+
func ContainerAddr0(name string, privatePort uint16) string {
222+
return ContainerAddrWithHost(name, privatePort, "0.0.0.0")
223+
}
224+
225+
func ContainerAddr(name string, privatePort uint16) string {
226+
return ContainerAddrWithHost(name, privatePort, "localhost")
219227
}
220228

221229
// DockerStart starts the specified services.

0 commit comments

Comments
 (0)