Skip to content

Commit

Permalink
Adding some unit tests to check of correct identification of Distinct…
Browse files Browse the repository at this point in the history
… method data usage
  • Loading branch information
kellrott committed Dec 19, 2019
1 parent 8017cd8 commit 8c21595
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions engine/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func PipelineStepOutputs(stmts []*gripql.GraphStatement) map[string][]string {
fields := protoutil.AsStringList(gs.GetDistinct())
for _, f := range fields {
n := jsonpath.GetNamespace(f)
if n == "__current__" {
out[steps[i]] = []string{"*"}
}
if a, ok := asMap[n]; ok {
out[a] = []string{"*"}
}
Expand Down
38 changes: 38 additions & 0 deletions engine/inspect/test/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,41 @@ func TestPathFind(t *testing.T) {
}
}
}

func TestDistinct(t *testing.T) {
q := gripql.NewQuery()
o := q.V().HasLabel("Person").As("person").Out("friend").Distinct("$person.name", "$.name").Count()
out := inspect.PipelineStepOutputs(o.Statements)
fmt.Printf("%#v\n", out)

if x, ok := out["2"]; ok {
if !setcmp.ContainsString(x, "*") {
t.Errorf("Required data from step 2 not recognized")
}
} else {
t.Errorf("Data load for step 2 not recognized")
}

o = q.V().HasLabel("Person").As("person").Out("friend").Distinct("$.name").Count()
out = inspect.PipelineStepOutputs(o.Statements)
fmt.Printf("%#v\n", out)
if x, ok := out["2"]; ok {
if !setcmp.ContainsString(x, "*") {
t.Errorf("Required data from step 2 not recognized")
}
} else {
t.Errorf("Data load for step 2 not recognized")
}

o = q.V().HasLabel("Person").As("person").Out("friend").Distinct("$person.name").Out("friend").Distinct("$.name").Count()
out = inspect.PipelineStepOutputs(o.Statements)
fmt.Printf("%#v\n", out)
if x, ok := out["3"]; ok {
if !setcmp.ContainsString(x, "*") {
t.Errorf("Required data from step 3 not recognized")
}
} else {
t.Errorf("Data load for step 3 not recognized")
}

}

0 comments on commit 8c21595

Please sign in to comment.