Skip to content

Commit

Permalink
addSpecifiedData method did not rebind objects correctly. This change c…
Browse files Browse the repository at this point in the history
…loses #41 by fixing the bug introduced by a typo on the object checking.
  • Loading branch information
xllora committed May 24, 2016
1 parent 276e980 commit 039c42c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bql/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (p *queryPlan) addSpecifiedData(ctx context.Context, r table.Row, cls *sema
lo = nlo
}
if cls.O == nil {
v := getBindedValueForComponent(r, []string{cls.PBinding, cls.PAlias})
v := getBindedValueForComponent(r, []string{cls.OBinding, cls.OAlias})
if v != nil {
o, err := cellToObject(v)
if err == nil {
Expand Down
49 changes: 49 additions & 0 deletions bql/planner/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,52 @@ func TestPlannerQuery(t *testing.T) {
}
}
}

func TestTreeTravesalToRoot(t *testing.T) {
// Graph traversal data.
traversalTriples := `/person<Gavin Belson> "born in"@[] /city<Springfield>
/person<Gavin Belson> "parent of"@[] /person<Peter Belson>
/person<Gavin Belson> "parent of"@[] /person<Mary Belson>
/person<Mary Belson> "parent of"@[] /person<Amy Schumer>
/person<Mary Belson> "parent of"@[] /person<Joe Schumer>`

traversalQuery := `SELECT ?grandparent
FROM ?test
WHERE {
?s "parent of"@[] /person<Amy Schumer> .
?grandparent "parent of"@[] ?s
};`

// Load traversing data
s, ctx := memory.NewStore(), context.Background()
g, gErr := s.NewGraph(ctx, "?test")
if gErr != nil {
t.Fatalf("memory.NewGraph failed to create \"?test\" with error %v", gErr)
}
b := bytes.NewBufferString(traversalTriples)
if _, err := io.ReadIntoGraph(ctx, g, b, literal.DefaultBuilder()); err != nil {
t.Fatalf("io.ReadIntoGraph failed to read test graph with error %v", err)
}
p, pErr := grammar.NewParser(grammar.SemanticBQL())
if pErr != nil {
t.Fatalf("grammar.NewParser: should have produced a valid BQL parser with error %v", pErr)
}
st := &semantic.Statement{}
if err := p.Parse(grammar.NewLLk(traversalQuery, 1), st); err != nil {
t.Errorf("Parser.consume: failed to parse query %q with error %v", traversalQuery, err)
}
plnr, err := New(ctx, s, st, 0)
if err != nil {
t.Errorf("planner.New failed to create a valid query plan with error %v", err)
}
tbl, err := plnr.Excecute(ctx)
if err != nil {
t.Errorf("planner.Excecute failed for query %q with error %v", traversalQuery, err)
}
if got, want := len(tbl.Bindings()), 1; got != want {
t.Errorf("tbl.Bindings returned the wrong number of bindings for %q; got %d, want %d", traversalQuery, got, want)
}
if got, want := len(tbl.Rows()), 1; got != want {
t.Errorf("planner.Excecute failed to return the expected number of rows for query %q; got %d want %d\nGot:\n%v\n", traversalQuery, got, want, tbl)
}
}

0 comments on commit 039c42c

Please sign in to comment.