Skip to content

Commit 039c42c

Browse files
committed
addSpecifiedData method did not rebind objects correctly. This change closes #41 by fixing the bug introduced by a typo on the object checking.
1 parent 276e980 commit 039c42c

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

bql/planner/planner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func (p *queryPlan) addSpecifiedData(ctx context.Context, r table.Row, cls *sema
298298
lo = nlo
299299
}
300300
if cls.O == nil {
301-
v := getBindedValueForComponent(r, []string{cls.PBinding, cls.PAlias})
301+
v := getBindedValueForComponent(r, []string{cls.OBinding, cls.OAlias})
302302
if v != nil {
303303
o, err := cellToObject(v)
304304
if err == nil {

bql/planner/planner_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,52 @@ func TestPlannerQuery(t *testing.T) {
470470
}
471471
}
472472
}
473+
474+
func TestTreeTravesalToRoot(t *testing.T) {
475+
// Graph traversal data.
476+
traversalTriples := `/person<Gavin Belson> "born in"@[] /city<Springfield>
477+
/person<Gavin Belson> "parent of"@[] /person<Peter Belson>
478+
/person<Gavin Belson> "parent of"@[] /person<Mary Belson>
479+
/person<Mary Belson> "parent of"@[] /person<Amy Schumer>
480+
/person<Mary Belson> "parent of"@[] /person<Joe Schumer>`
481+
482+
traversalQuery := `SELECT ?grandparent
483+
FROM ?test
484+
WHERE {
485+
?s "parent of"@[] /person<Amy Schumer> .
486+
?grandparent "parent of"@[] ?s
487+
};`
488+
489+
// Load traversing data
490+
s, ctx := memory.NewStore(), context.Background()
491+
g, gErr := s.NewGraph(ctx, "?test")
492+
if gErr != nil {
493+
t.Fatalf("memory.NewGraph failed to create \"?test\" with error %v", gErr)
494+
}
495+
b := bytes.NewBufferString(traversalTriples)
496+
if _, err := io.ReadIntoGraph(ctx, g, b, literal.DefaultBuilder()); err != nil {
497+
t.Fatalf("io.ReadIntoGraph failed to read test graph with error %v", err)
498+
}
499+
p, pErr := grammar.NewParser(grammar.SemanticBQL())
500+
if pErr != nil {
501+
t.Fatalf("grammar.NewParser: should have produced a valid BQL parser with error %v", pErr)
502+
}
503+
st := &semantic.Statement{}
504+
if err := p.Parse(grammar.NewLLk(traversalQuery, 1), st); err != nil {
505+
t.Errorf("Parser.consume: failed to parse query %q with error %v", traversalQuery, err)
506+
}
507+
plnr, err := New(ctx, s, st, 0)
508+
if err != nil {
509+
t.Errorf("planner.New failed to create a valid query plan with error %v", err)
510+
}
511+
tbl, err := plnr.Excecute(ctx)
512+
if err != nil {
513+
t.Errorf("planner.Excecute failed for query %q with error %v", traversalQuery, err)
514+
}
515+
if got, want := len(tbl.Bindings()), 1; got != want {
516+
t.Errorf("tbl.Bindings returned the wrong number of bindings for %q; got %d, want %d", traversalQuery, got, want)
517+
}
518+
if got, want := len(tbl.Rows()), 1; got != want {
519+
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)
520+
}
521+
}

0 commit comments

Comments
 (0)