Skip to content

Commit

Permalink
Cherry pick PR #3205 into release/v1.0 branch. (#4143)
Browse files Browse the repository at this point in the history
This fixes #3807.
  • Loading branch information
martinmr authored Oct 14, 2019
1 parent 747ee5c commit 8299915
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 17 deletions.
4 changes: 4 additions & 0 deletions query/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ symbol : string @index(exact) .
room : string @index(term) .
office.room : uid .
number : int @index(int) .
node : uid .
`

err := schema.ParseBytes([]byte(schemaStr), 1)
Expand Down Expand Up @@ -673,4 +674,7 @@ number : int @index(int) .
addEdgeToUID(t, "office.room", 4001, 4002, nil)
addEdgeToUID(t, "office.room", 4001, 4003, nil)
addEdgeToUID(t, "office.room", 4001, 4004, nil)

addEdgeToValue(t, "name", 11100, "expand", nil)
addEdgeToUID(t, "node", 11100, 11100, nil)
}
35 changes: 18 additions & 17 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1969,23 +1969,6 @@ func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error) {
}
}

if sg.DestUIDs == nil || len(sg.DestUIDs.Uids) == 0 {
// Looks like we're done here. Be careful with nil srcUIDs!
if span != nil {
span.Annotatef(nil, "Zero uids for %q", sg.Attr)
}
out := sg.Children[:0]
for _, child := range sg.Children {
if child.IsInternal() && child.Attr == "expand" {
continue
}
out = append(out, child)
}
sg.Children = out // Remove any expand nodes we might have added.
rch <- nil
return
}

// Run filters if any.
if len(sg.Filters) > 0 {
// Run all filters in parallel.
Expand Down Expand Up @@ -2135,6 +2118,24 @@ func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error) {
childErr = err
}
}

if sg.DestUIDs == nil || len(sg.DestUIDs.Uids) == 0 {
// Looks like we're done here. Be careful with nil srcUIDs!
if span != nil {
span.Annotatef(nil, "Zero uids for %q", sg.Attr)
}
out := sg.Children[:0]
for _, child := range sg.Children {
if child.IsInternal() && child.Attr == "expand" {
continue
}
out = append(out, child)
}
sg.Children = out // Remove any expand nodes we might have added.
rch <- nil
return
}

rch <- childErr
}

Expand Down
85 changes: 85 additions & 0 deletions query/query3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,3 +1778,88 @@ func TestFilterRegex16(t *testing.T) {
`{"data": {"me":[{"name@ru":"Артём Ткаченко"}]}}`,
js)
}

func TestNestedExpandAll(t *testing.T) {
query := `{
q(func: has(node)) {
uid
expand(_all_) {
uid
node {
uid
expand(_all_)
}
}
}
}`
js := processToFastJsonNoErr(t, query)
require.JSONEq(t, `{"data": {
"q": [
{
"uid": "0x2b5c",
"name": "expand",
"node": [
{
"uid": "0x2b5c",
"node": [
{
"uid": "0x2b5c",
"name": "expand"
}
]
}
]
}
]}}`, js)
}

func TestNoResultsFilter(t *testing.T) {
query := `{
q(func: has(nonexistent_pred)) @filter(le(name, "abc")) {
uid
}
}`
js := processToFastJsonNoErr(t, query)
require.JSONEq(t, `{"data": {"q": []}}`, js)
}

func TestNoResultsPagination(t *testing.T) {
query := `{
q(func: has(nonexistent_pred), first: 50) {
uid
}
}`
js := processToFastJsonNoErr(t, query)
require.JSONEq(t, `{"data": {"q": []}}`, js)
}

func TestNoResultsGroupBy(t *testing.T) {
query := `{
q(func: has(nonexistent_pred)) @groupby(name) {
count(uid)
}
}`
js := processToFastJsonNoErr(t, query)
require.JSONEq(t, `{"data": {}}`, js)
}

func TestNoResultsOrder(t *testing.T) {
query := `{
q(func: has(nonexistent_pred), orderasc: name) {
uid
}
}`
js := processToFastJsonNoErr(t, query)
require.JSONEq(t, `{"data": {"q": []}}`, js)
}

func TestNoResultsCount(t *testing.T) {
query := `{
q(func: has(nonexistent_pred)) {
uid
count(friend)
}
}`
js := processToFastJsonNoErr(t, query)
require.JSONEq(t, `{"data": {"q": []}}`, js)
}

0 comments on commit 8299915

Please sign in to comment.