Skip to content

Commit

Permalink
fix(core): Fix regression in computing cond variables (#9126)
Browse files Browse the repository at this point in the history
Fixes: #9125
  • Loading branch information
harshil-goel committed Aug 8, 2024
1 parent cc4d474 commit a274431
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
6 changes: 3 additions & 3 deletions graphql/e2e/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import (
)

var (
groupOneHTTP = testutil.ContainerAddr("alpha1", 8080)
groupTwoHTTP = testutil.ContainerAddr("alpha2", 8080)
groupThreeHTTP = testutil.ContainerAddr("alpha3", 8080)
groupOneHTTP = testutil.ContainerAddr0("alpha1", 8080)
groupTwoHTTP = testutil.ContainerAddr0("alpha2", 8080)
groupThreeHTTP = testutil.ContainerAddr0("alpha3", 8080)
groupOnegRPC = testutil.SockAddr

groupOneGraphQLServer = "http://" + groupOneHTTP + "/graphql"
Expand Down
23 changes: 23 additions & 0 deletions query/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ tweet-c : string @index(fulltext) .
tweet-d : string @index(trigram) .
name2 : string @index(term) .
age2 : int @index(int) .
DispatchBoard.column: uid @reverse .
order: int .
type DispatchBoardColumn {
name
}
type DispatchBoardCard {
DispatchBoard.column
order
}
`

func populateCluster(dc dgraphapi.Cluster) {
Expand Down Expand Up @@ -892,6 +905,16 @@ func populateCluster(dc dgraphapi.Cluster) {
<40> <name2> "Alice" .
<41> <age2> "20" .
<1023> <dgraph.type> "DispatchBoardColumn" .
<1024> <dgraph.type> "DispatchBoardColumn" .
<1025> <dgraph.type> "DispatchBoardCard" .
<1026> <dgraph.type> "DispatchBoardCard" .
<1025> <DispatchBoard.column> <1023> .
<1025> <order> "0" .
<1026> <DispatchBoard.column> <1023> .
<1026> <order> "1" .
`)
x.Panic(err)

Expand Down
7 changes: 0 additions & 7 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,13 +1185,6 @@ func (sg *SubGraph) transformVars(doneVars map[string]varValue, path []*SubGraph
mt.Const = val
continue
}
// TODO: Need to understand why certain aggregations map to uid = 0
// while others map to uid = MaxUint64
if val, ok := newMap[0]; ok && len(newMap) == 1 {
mt.Const = val
continue
}

mt.Val = newMap
}
return nil
Expand Down
40 changes: 40 additions & 0 deletions query/query0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3547,6 +3547,46 @@ func TestEqFilterWithoutIndex(t *testing.T) {

}

func TestCondCondition(t *testing.T) {
tests := []struct {
name string
query string
expected string
}{
{
`Test Cond`,
`{
var(func: uid(0x3ff)) {
columnUid as uid
~DispatchBoard.column { o as order }
cards as count(~DispatchBoard.column)
}
var() {
lastPosition as max(val(o))
cardCount as max(val(cards))
nextPosition as math(cond(cardCount==0, 0, lastPosition+1))
}
q(func: uid(columnUid)) {
val(lastPosition)
val(cardCount)
val(nextPosition)
uid
}
}`,
`{"data":{"q": [{"uid": "0x3ff"}] }}`,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := processQueryNoErr(t, tc.query)
require.JSONEq(t, tc.expected, result)
})
}
}

func TestMatchingWithPagination(t *testing.T) {
tests := []struct {
name string
Expand Down
14 changes: 11 additions & 3 deletions testutil/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,22 @@ func AllContainers(prefix string) []types.Container {
return out
}

func ContainerAddr(name string, privatePort uint16) string {
func ContainerAddrWithHost(name string, privatePort uint16, host string) string {
c := getContainer(name)
for _, p := range c.Ports {
if p.PrivatePort == privatePort {
return "localhost:" + strconv.Itoa(int(p.PublicPort))
return host + ":" + strconv.Itoa(int(p.PublicPort))
}
}
return "localhost:" + strconv.Itoa(int(privatePort))
return host + ":" + strconv.Itoa(int(privatePort))
}

func ContainerAddr0(name string, privatePort uint16) string {
return ContainerAddrWithHost(name, privatePort, "0.0.0.0")
}

func ContainerAddr(name string, privatePort uint16) string {
return ContainerAddrWithHost(name, privatePort, "localhost")
}

// DockerStart starts the specified services.
Expand Down

0 comments on commit a274431

Please sign in to comment.