diff --git a/query/query.go b/query/query.go index 21d94b4b3aa..753e3c1687e 100644 --- a/query/query.go +++ b/query/query.go @@ -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. @@ -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 } diff --git a/query/query0_test.go b/query/query0_test.go index ae78ee6b047..a42bc576e87 100644 --- a/query/query0_test.go +++ b/query/query0_test.go @@ -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())