Reduce TripleStore interface names
This commit is contained in:
parent
8576f66d20
commit
b89d4f392c
29 changed files with 156 additions and 156 deletions
|
|
@ -126,13 +126,13 @@ func (it *HasA) DebugString(indent int) string {
|
|||
func (it *HasA) Check(val graph.TSVal) bool {
|
||||
graph.CheckLogIn(it, val)
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infoln("Id is", it.ts.GetNameFor(val))
|
||||
glog.V(4).Infoln("Id is", it.ts.NameOf(val))
|
||||
}
|
||||
// TODO(barakmich): Optimize this
|
||||
if it.resultIt != nil {
|
||||
it.resultIt.Close()
|
||||
}
|
||||
it.resultIt = it.ts.GetTripleIterator(it.dir, val)
|
||||
it.resultIt = it.ts.TripleIterator(it.dir, val)
|
||||
return graph.CheckLogOut(it, val, it.GetCheckResult())
|
||||
}
|
||||
|
||||
|
|
@ -146,10 +146,10 @@ func (it *HasA) GetCheckResult() bool {
|
|||
break
|
||||
}
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infoln("Triple is", it.ts.GetTriple(linkVal))
|
||||
glog.V(4).Infoln("Triple is", it.ts.Triple(linkVal))
|
||||
}
|
||||
if it.primaryIt.Check(linkVal) {
|
||||
it.Last = it.ts.GetTripleDirection(linkVal, it.dir)
|
||||
it.Last = it.ts.TripleDirection(linkVal, it.dir)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -184,8 +184,8 @@ func (it *HasA) Next() (graph.TSVal, bool) {
|
|||
if !ok {
|
||||
return graph.NextLogOut(it, 0, false)
|
||||
}
|
||||
name := it.ts.GetTriple(tID).Get(it.dir)
|
||||
val := it.ts.GetIdFor(name)
|
||||
name := it.ts.Triple(tID).Get(it.dir)
|
||||
val := it.ts.ValueOf(name)
|
||||
it.Last = val
|
||||
return graph.NextLogOut(it, val, true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func (it *LinksTo) DebugString(indent int) string {
|
|||
// for the LinksTo.
|
||||
func (it *LinksTo) Check(val graph.TSVal) bool {
|
||||
graph.CheckLogIn(it, val)
|
||||
node := it.ts.GetTripleDirection(val, it.dir)
|
||||
node := it.ts.TripleDirection(val, it.dir)
|
||||
if it.primaryIt.Check(node) {
|
||||
it.Last = val
|
||||
return graph.CheckLogOut(it, val, true)
|
||||
|
|
@ -146,7 +146,7 @@ func (it *LinksTo) Next() (graph.TSVal, bool) {
|
|||
return graph.NextLogOut(it, 0, false)
|
||||
}
|
||||
it.nextIt.Close()
|
||||
it.nextIt = it.ts.GetTripleIterator(it.dir, candidate)
|
||||
it.nextIt = it.ts.TripleIterator(it.dir, candidate)
|
||||
// Recurse -- return the first in the next set.
|
||||
return it.Next()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,16 +24,16 @@ func TestLinksTo(t *testing.T) {
|
|||
ts := new(TestTripleStore)
|
||||
tsFixed := newFixed()
|
||||
tsFixed.AddValue(2)
|
||||
ts.On("GetIdFor", "cool").Return(1)
|
||||
ts.On("GetTripleIterator", graph.Object, 1).Return(tsFixed)
|
||||
ts.On("ValueOf", "cool").Return(1)
|
||||
ts.On("TripleIterator", graph.Object, 1).Return(tsFixed)
|
||||
fixed := newFixed()
|
||||
fixed.AddValue(ts.GetIdFor("cool"))
|
||||
fixed.AddValue(ts.ValueOf("cool"))
|
||||
lto := NewLinksTo(ts, fixed, graph.Object)
|
||||
val, ok := lto.Next()
|
||||
if !ok {
|
||||
t.Error("At least one triple matches the fixed object")
|
||||
}
|
||||
if val != 2 {
|
||||
t.Errorf("Triple index 2, such as %s, should match %s", ts.GetTriple(2), ts.GetTriple(val))
|
||||
t.Errorf("Triple index 2, such as %s, should match %s", ts.Triple(2), ts.Triple(val))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,23 +27,23 @@ type TestTripleStore struct {
|
|||
mock.Mock
|
||||
}
|
||||
|
||||
func (ts *TestTripleStore) GetIdFor(s string) graph.TSVal {
|
||||
func (ts *TestTripleStore) ValueOf(s string) graph.TSVal {
|
||||
args := ts.Mock.Called(s)
|
||||
return args.Get(0)
|
||||
}
|
||||
func (ts *TestTripleStore) AddTriple(*graph.Triple) {}
|
||||
func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {}
|
||||
func (ts *TestTripleStore) GetTriple(graph.TSVal) *graph.Triple { return &graph.Triple{} }
|
||||
func (ts *TestTripleStore) GetTripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator {
|
||||
func (ts *TestTripleStore) AddTriple(*graph.Triple) {}
|
||||
func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {}
|
||||
func (ts *TestTripleStore) Triple(graph.TSVal) *graph.Triple { return &graph.Triple{} }
|
||||
func (ts *TestTripleStore) TripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator {
|
||||
args := ts.Mock.Called(d, i)
|
||||
return args.Get(0).(graph.Iterator)
|
||||
}
|
||||
func (ts *TestTripleStore) GetNodesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (ts *TestTripleStore) GetTriplesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (ts *TestTripleStore) NodesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (ts *TestTripleStore) TriplesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (ts *TestTripleStore) GetIteratorByString(string, string, string) graph.Iterator {
|
||||
return &Null{}
|
||||
}
|
||||
func (ts *TestTripleStore) GetNameFor(v graph.TSVal) string {
|
||||
func (ts *TestTripleStore) NameOf(v graph.TSVal) string {
|
||||
args := ts.Mock.Called(v)
|
||||
return args.Get(0).(string)
|
||||
}
|
||||
|
|
@ -55,6 +55,6 @@ func (ts *TestTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator,
|
|||
func (ts *TestTripleStore) FixedIterator() graph.FixedIterator {
|
||||
return NewFixedIteratorWithCompare(BasicEquality)
|
||||
}
|
||||
func (ts *TestTripleStore) Close() {}
|
||||
func (ts *TestTripleStore) GetTripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 }
|
||||
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}
|
||||
func (ts *TestTripleStore) Close() {}
|
||||
func (ts *TestTripleStore) TripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 }
|
||||
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ func (qs *queryShape) MakeNode(it graph.Iterator) *Node {
|
|||
if !more {
|
||||
break
|
||||
}
|
||||
n.Values = append(n.Values, qs.ts.GetNameFor(val))
|
||||
n.Values = append(n.Values, qs.ts.NameOf(val))
|
||||
}
|
||||
case "hasa":
|
||||
hasa := it.(*HasA)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import (
|
|||
func buildHasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
||||
fixed_obj := ts.FixedIterator()
|
||||
fixed_pred := ts.FixedIterator()
|
||||
fixed_obj.AddValue(ts.GetIdFor(target))
|
||||
fixed_pred.AddValue(ts.GetIdFor("status"))
|
||||
fixed_obj.AddValue(ts.ValueOf(target))
|
||||
fixed_pred.AddValue(ts.ValueOf("status"))
|
||||
fixed_obj.AddTag(tag)
|
||||
lto1 := NewLinksTo(ts, fixed_obj, graph.Object)
|
||||
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
|
||||
|
|
@ -40,14 +40,14 @@ func buildHasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
|||
func TestQueryShape(t *testing.T) {
|
||||
var queryShape map[string]interface{}
|
||||
ts := new(TestTripleStore)
|
||||
ts.On("GetIdFor", "cool").Return(1)
|
||||
ts.On("GetNameFor", 1).Return("cool")
|
||||
ts.On("GetIdFor", "status").Return(2)
|
||||
ts.On("GetNameFor", 2).Return("status")
|
||||
ts.On("GetIdFor", "fun").Return(3)
|
||||
ts.On("GetNameFor", 3).Return("fun")
|
||||
ts.On("GetIdFor", "name").Return(4)
|
||||
ts.On("GetNameFor", 4).Return("name")
|
||||
ts.On("ValueOf", "cool").Return(1)
|
||||
ts.On("NameOf", 1).Return("cool")
|
||||
ts.On("ValueOf", "status").Return(2)
|
||||
ts.On("NameOf", 2).Return("status")
|
||||
ts.On("ValueOf", "fun").Return(3)
|
||||
ts.On("NameOf", 3).Return("fun")
|
||||
ts.On("ValueOf", "name").Return(4)
|
||||
ts.On("NameOf", 4).Return("name")
|
||||
|
||||
Convey("Given a single linkage iterator's shape", t, func() {
|
||||
queryShape = make(map[string]interface{})
|
||||
|
|
@ -92,7 +92,7 @@ func TestQueryShape(t *testing.T) {
|
|||
andInternal.AddSubIterator(hasa1)
|
||||
andInternal.AddSubIterator(hasa2)
|
||||
fixed_pred := ts.FixedIterator()
|
||||
fixed_pred.AddValue(ts.GetIdFor("name"))
|
||||
fixed_pred.AddValue(ts.ValueOf("name"))
|
||||
lto1 := NewLinksTo(ts, andInternal, graph.Subject)
|
||||
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
|
||||
and := NewAnd()
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func NewComparison(sub graph.Iterator, op Operator, val interface{}, ts graph.Tr
|
|||
// and our operator, determine whether or not we meet the requirement.
|
||||
func (it *Comparison) doComparison(val graph.TSVal) bool {
|
||||
//TODO(barakmich): Implement string comparison.
|
||||
nodeStr := it.ts.GetNameFor(val)
|
||||
nodeStr := it.ts.NameOf(val)
|
||||
switch cVal := it.val.(type) {
|
||||
case int:
|
||||
cInt := int64(cVal)
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ import (
|
|||
func SetupMockTripleStore(nameMap map[string]int) *TestTripleStore {
|
||||
ts := new(TestTripleStore)
|
||||
for k, v := range nameMap {
|
||||
ts.On("GetIdFor", k).Return(v)
|
||||
ts.On("GetNameFor", v).Return(k)
|
||||
ts.On("ValueOf", k).Return(v)
|
||||
ts.On("NameOf", v).Return(k)
|
||||
}
|
||||
return ts
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ func checkIteratorContains(ts graph.TripleStore, it graph.Iterator, expected []s
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
actual = append(actual, ts.GetNameFor(val))
|
||||
actual = append(actual, ts.NameOf(val))
|
||||
}
|
||||
actualSet := actual[:]
|
||||
for _, a := range expected {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue