Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic due to nil maps #3042

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,7 @@ func (sg *SubGraph) populateUidValVar(doneVars map[string]varValue, sgPath []*Su
doneVars[sg.Params.Var] = varValue{
strList: sg.valueMatrix,
path: sgPath,
Vals: make(map[uint64]types.Val),
}
} else if len(sg.counts) > 0 {
// This implies it is a value variable.
Expand Down Expand Up @@ -1532,6 +1533,7 @@ func (sg *SubGraph) populateUidValVar(doneVars map[string]varValue, sgPath []*Su
doneVars[sg.Params.Var] = varValue{
Uids: uids,
path: sgPath,
Vals: make(map[uint64]types.Val),
}
return nil
}
Expand Down
31 changes: 31 additions & 0 deletions query/query0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,37 @@ func TestCountUidToVarCombinedWithNormalVar(t *testing.T) {
require.JSONEq(t, `{"data": {"me":[{"score": 5}]}}`, js)
}

func TestDefaultValueVar1(t *testing.T) {
query := `
{
var(func: has(pred)) {
n as uid
cnt as count(_predicate_)
}

data(func: uid(n)) @filter(gt(val(cnt), 4)) {
expand(_all_)
}
}`
js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"data":[]}}`, js)
}

func TestDefaultValueVar2(t *testing.T) {
query := `
{
var(func: uid(0x1)) {
cnt as _predicate_
}

data(func: uid(0x1)) {
val(cnt)
}
}`
js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"data":[]}}`, js)
}

func TestMain(m *testing.M) {
populateCluster()
os.Exit(m.Run())
Expand Down