Move iterators into separate package
Also reduce API exposure and use standard library more - and fix bugs I previously introduces in mongo.
This commit is contained in:
parent
88be6bee37
commit
1768e593a8
62 changed files with 3240 additions and 3130 deletions
|
|
@ -23,10 +23,11 @@ import (
|
|||
"labix.org/v2/mgo/bson"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/graph/iterator"
|
||||
)
|
||||
|
||||
type Iterator struct {
|
||||
graph.BaseIterator
|
||||
iterator.Base
|
||||
ts *TripleStore
|
||||
dir graph.Direction
|
||||
iter *mgo.Iter
|
||||
|
|
@ -40,7 +41,7 @@ type Iterator struct {
|
|||
|
||||
func NewIterator(ts *TripleStore, collection string, d graph.Direction, val graph.TSVal) *Iterator {
|
||||
var m Iterator
|
||||
graph.BaseIteratorInit(&m.BaseIterator)
|
||||
iterator.BaseInit(&m.Base)
|
||||
|
||||
m.name = ts.GetNameFor(val)
|
||||
m.collection = collection
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"github.com/barakmich/glog"
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/graph/iterator"
|
||||
)
|
||||
|
||||
const DefaultDBName = "cayley"
|
||||
|
|
@ -214,11 +215,12 @@ func (ts *TripleStore) GetTriple(val graph.TSVal) *graph.Triple {
|
|||
if err != nil {
|
||||
log.Println("Error: Couldn't retrieve triple", val.(string), err)
|
||||
}
|
||||
return graph.MakeTriple(
|
||||
bsonDoc["Sub"].(string),
|
||||
bsonDoc["Pred"].(string),
|
||||
bsonDoc["Obj"].(string),
|
||||
bsonDoc["Provenance"].(string))
|
||||
return &graph.Triple{
|
||||
bsonDoc["Subject"].(string),
|
||||
bsonDoc["Predicate"].(string),
|
||||
bsonDoc["Object"].(string),
|
||||
bsonDoc["Provenance"].(string),
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
||||
|
|
@ -264,8 +266,8 @@ func compareStrings(a, b graph.TSVal) bool {
|
|||
return a.(string) == b.(string)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) MakeFixed() *graph.FixedIterator {
|
||||
return graph.NewFixedIteratorWithCompare(compareStrings)
|
||||
func (ts *TripleStore) FixedIterator() graph.FixedIterator {
|
||||
return iterator.NewFixedIteratorWithCompare(compareStrings)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) Close() {
|
||||
|
|
@ -303,9 +305,9 @@ func (ts *TripleStore) BulkLoad(t_chan chan *graph.Triple) {
|
|||
var p_key = this["_id"].slice(len / 4, 2 * len / 4)
|
||||
var o_key = this["_id"].slice(2 * len / 4, 3 * len / 4)
|
||||
var c_key = this["_id"].slice(3 * len / 4)
|
||||
emit(s_key, {"_id": s_key, "Name" : this.Sub, "Size" : 1})
|
||||
emit(p_key, {"_id": p_key, "Name" : this.Pred, "Size" : 1})
|
||||
emit(o_key, {"_id": o_key, "Name" : this.Obj, "Size" : 1})
|
||||
emit(s_key, {"_id": s_key, "Name" : this.Subject, "Size" : 1})
|
||||
emit(p_key, {"_id": p_key, "Name" : this.Predicate, "Size" : 1})
|
||||
emit(o_key, {"_id": o_key, "Name" : this.Object, "Size" : 1})
|
||||
if (this.Provenance != "") {
|
||||
emit(c_key, {"_id": c_key, "Name" : this.Provenance, "Size" : 1})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,18 +16,19 @@ package mongo
|
|||
|
||||
import (
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/graph/iterator"
|
||||
)
|
||||
|
||||
func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
||||
switch it.Type() {
|
||||
case "linksto":
|
||||
return ts.optimizeLinksTo(it.(*graph.LinksToIterator))
|
||||
return ts.optimizeLinksTo(it.(*iterator.LinksTo))
|
||||
|
||||
}
|
||||
return it, false
|
||||
}
|
||||
|
||||
func (ts *TripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
||||
func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bool) {
|
||||
subs := it.GetSubIterators()
|
||||
if len(subs) != 1 {
|
||||
return it, false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue