Skip to content

Implemented planner for the CONSTRUCT statement.#76

Merged
xllora merged 3 commits into
google:masterfrom
apr94:construct_planner
Jul 7, 2017
Merged

Implemented planner for the CONSTRUCT statement.#76
xllora merged 3 commits into
google:masterfrom
apr94:construct_planner

Conversation

@apr94
Copy link
Copy Markdown
Contributor

@apr94 apr94 commented Jun 19, 2017

The planner for the construct statement + tests. Also the triples loading for tests has been refactored so that all test cases can use a single method.

Copy link
Copy Markdown
Member

@xllora xllora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments. Also thanks for keep fixing all those typos I left sprinkled everywhere :/

Comment thread bql/planner/planner.go Outdated
var ts []*triple.Triple
for _, cc := range p.stm.ConstructClauses() {
for _, r := range tbl.Rows() {
sbj, prd, obj := cc.S, cc.P, cc.O
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very long function. Can you break the logic inside the look into smaller, easier to follow functions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I can refactor this further when I refactor the construct and reification clauses into a single struct in a follow-up PR.

Comment thread bql/planner/planner.go Outdated
trace(p.tracer, func() []string {
return []string{"Inserting triples to graph \"" + g.ID(ctx) + "\""}
})
return g.AddTriples(ctx, d)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can run on large collections of data. I would suggest that instead of pilling them up on a large slice, you pass them in a channel where you have a goroutine consuming it. See how buffered channels are used elsewhere. This would also help batch the inserts into the the gorouting doing a few calls to AddTriples instead of a big one. You can make the case that the table can also be big, yes, that is something I have on the todo to revisit :/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Let me know if it looks fine.

Comment thread bql/planner/planner.go
})
}

func (p *constructPlan) String() string {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner_test.go Outdated
trps: sts + dts,
},
{
s: `construct {?s "met"@[] ?o; "location"@[] /city<New York>} into ?dest from ?src where {?s "met"@[] ?o};`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please break the construct queries into multiple lines?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner_test.go Outdated
}
}

func TestPlannerConstruct(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add one more test to check that the triples returned are the ones expected, not only the right number?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Since we do not know what the blank node id is going to be, I had to add a lot of logic here to match place holder blank nodes to blank nodes generated by triples.go. Let me know if looks fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I ran this test with -count=100 to ensure that there was no flakiness.

@apr94
Copy link
Copy Markdown
Contributor Author

apr94 commented Jul 6, 2017

Thanks for the review. PTAL, I have addressed your comments!

Copy link
Copy Markdown
Member

@xllora xllora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of suggestions and minor nits.

Comment thread bql/planner/planner.go Outdated
done := make(chan bool)

go func() {
ts := []*triple.Triple{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer

var ts []*tripleTriple

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner.go Outdated
}
for elem := range tripChan {
ts = append(ts, elem)
if len(ts) >= 10 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use bulk triple op instead of hardcoding 10?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Have plumbed BulkTripleOpSize through to here and ensured that all tests pass and bw compiles and runs.

Comment thread bql/planner/planner.go Outdated

for _, cc := range p.stm.ConstructClauses() {
for _, r := range tbl.Rows() {
sbj, prd, obj := cc.S, cc.P, cc.O
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the code in the loop into a separate function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner.go Outdated
}
if prd == nil {
if tbl.HasBinding(cc.PBinding) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank new line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner.go Outdated
}
if obj == nil {
if tbl.HasBinding(cc.OBinding) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank new line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner.go Outdated
}
prd = v.P
} else if cc.PTemporal && cc.PAnchorBinding != "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank new line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner.go Outdated
}
obj = co
} else if cc.OTemporal && cc.OAnchorBinding != "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank new line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner.go Outdated
return nil, err
}
if len(cc.ReificationClauses()) > 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank new line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bql/planner/planner_test.go Outdated
bql := `construct {?s "met"@[?t] ?o; "location"@[] /city<New York>;
"outcome"@[] "good"^^type:text.
?s "connected_to"@[] ?o }
into ?dest
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment is off :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops..gonna blame Vim for this one :)

fmt.Sprintf("%s\t%s\t%s", `/_<b2>`, `"outcome"@[]`, `"good"^^type:text`): false,
}

// First, we map each blank node generated to a potential blank node placeholder (such as b1 or b2.)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this complex testing because the blank nodes are unique and randomly generated right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. It could be avoided if we can mock uuid.NewRandom() to produce deterministic output, though currently this setup is pretty verbose and informative when the set of stored triples are not as expected. Do you think it worth exploring the mocking route?

@apr94
Copy link
Copy Markdown
Contributor Author

apr94 commented Jul 6, 2017

PTAL, I have addressed the review comments!

@xllora xllora merged commit f6292b4 into google:master Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants