Skip to content
Snippets Groups Projects
Commit f2a1d876 authored by Manish R Jain's avatar Manish R Jain
Browse files

Switch naming from Triple to DirectedEdge

parent 9281dc09
Branches
No related tags found
No related merge requests found
...@@ -76,8 +76,8 @@ func Key(uid uint64, attr string) []byte { ...@@ -76,8 +76,8 @@ func Key(uid uint64, attr string) []byte {
return buf.Bytes() return buf.Bytes()
} }
func addTripleToPosting(b *flatbuffers.Builder, func addEdgeToPosting(b *flatbuffers.Builder,
t x.Triple, op byte) flatbuffers.UOffsetT { t x.DirectedEdge, op byte) flatbuffers.UOffsetT {
var bo flatbuffers.UOffsetT var bo flatbuffers.UOffsetT
if t.Value != nil { if t.Value != nil {
...@@ -405,19 +405,19 @@ func (l *List) generateIndex() { ...@@ -405,19 +405,19 @@ func (l *List) generateIndex() {
} }
func (l *List) addIfValid(b *flatbuffers.Builder, func (l *List) addIfValid(b *flatbuffers.Builder,
offsets *[]flatbuffers.UOffsetT, t x.Triple, op byte) { offsets *[]flatbuffers.UOffsetT, t x.DirectedEdge, op byte) {
if op == Del { if op == Del {
if fi := l.find(t.ValueId); fi >= 0 { if fi := l.find(t.ValueId); fi >= 0 {
// Delete. Only add it to the list if it exists in the posting list. // Delete. Only add it to the list if it exists in the posting list.
*offsets = append(*offsets, addTripleToPosting(b, t, op)) *offsets = append(*offsets, addEdgeToPosting(b, t, op))
} }
} else { } else {
*offsets = append(*offsets, addTripleToPosting(b, t, op)) *offsets = append(*offsets, addEdgeToPosting(b, t, op))
} }
} }
func (l *List) AddMutation(t x.Triple, op byte) error { func (l *List) AddMutation(t x.DirectedEdge, op byte) error {
l.mutex.Lock() l.mutex.Lock()
defer l.mutex.Unlock() defer l.mutex.Unlock()
...@@ -428,7 +428,7 @@ func (l *List) AddMutation(t x.Triple, op byte) error { ...@@ -428,7 +428,7 @@ func (l *List) AddMutation(t x.Triple, op byte) error {
// - If yes, store the mutation. // - If yes, store the mutation.
// - If no, disregard this mutation. // - If no, disregard this mutation.
// All triples with a value set, have the same uid. In other words, // All edges with a value set, have the same uid. In other words,
// an (entity, attribute) can only have one interface{} value. // an (entity, attribute) can only have one interface{} value.
if t.Value != nil { if t.Value != nil {
t.ValueId = math.MaxUint64 t.ValueId = math.MaxUint64
......
...@@ -70,12 +70,12 @@ func TestAddMutation(t *testing.T) { ...@@ -70,12 +70,12 @@ func TestAddMutation(t *testing.T) {
l.init(key, ps, ms) l.init(key, ps, ms)
triple := x.Triple{ edge := x.DirectedEdge{
ValueId: 9, ValueId: 9,
Source: "testing", Source: "testing",
Timestamp: time.Now(), Timestamp: time.Now(),
} }
if err := l.AddMutation(triple, Set); err != nil { if err := l.AddMutation(edge, Set); err != nil {
t.Error(err) t.Error(err)
} }
/* /*
...@@ -100,9 +100,9 @@ func TestAddMutation(t *testing.T) { ...@@ -100,9 +100,9 @@ func TestAddMutation(t *testing.T) {
} }
// return // Test 1. // return // Test 1.
// Add another triple now. // Add another edge now.
triple.ValueId = 81 edge.ValueId = 81
l.AddMutation(triple, Set) l.AddMutation(edge, Set)
// l.CommitIfDirty() // l.CommitIfDirty()
if l.Length() != 2 { if l.Length() != 2 {
t.Errorf("Length: %d", l.Length()) t.Errorf("Length: %d", l.Length())
...@@ -122,12 +122,12 @@ func TestAddMutation(t *testing.T) { ...@@ -122,12 +122,12 @@ func TestAddMutation(t *testing.T) {
} }
// return // Test 2. // return // Test 2.
// Add another triple, in between the two above. // Add another edge, in between the two above.
uids := []uint64{ uids := []uint64{
9, 49, 81, 9, 49, 81,
} }
triple.ValueId = 49 edge.ValueId = 49
if err := l.AddMutation(triple, Set); err != nil { if err := l.AddMutation(edge, Set); err != nil {
t.Error(err) t.Error(err)
} }
/* /*
...@@ -140,20 +140,20 @@ func TestAddMutation(t *testing.T) { ...@@ -140,20 +140,20 @@ func TestAddMutation(t *testing.T) {
} }
// return // Test 3. // return // Test 3.
// Delete a triple, add a triple, replace a triple // Delete an edge, add an edge, replace an edge
triple.ValueId = 49 edge.ValueId = 49
if err := l.AddMutation(triple, Del); err != nil { if err := l.AddMutation(edge, Del); err != nil {
t.Error(err) t.Error(err)
} }
triple.ValueId = 69 edge.ValueId = 69
if err := l.AddMutation(triple, Set); err != nil { if err := l.AddMutation(edge, Set); err != nil {
t.Error(err) t.Error(err)
} }
triple.ValueId = 9 edge.ValueId = 9
triple.Source = "anti-testing" edge.Source = "anti-testing"
if err := l.AddMutation(triple, Set); err != nil { if err := l.AddMutation(edge, Set); err != nil {
t.Error(err) t.Error(err)
} }
/* /*
...@@ -207,12 +207,12 @@ func TestAddMutation_Value(t *testing.T) { ...@@ -207,12 +207,12 @@ func TestAddMutation_Value(t *testing.T) {
ol.init(key, ps, ms) ol.init(key, ps, ms)
triple := x.Triple{ edge := x.DirectedEdge{
Value: "oh hey there", Value: "oh hey there",
Source: "new-testing", Source: "new-testing",
Timestamp: time.Now(), Timestamp: time.Now(),
} }
if err := ol.AddMutation(triple, Set); err != nil { if err := ol.AddMutation(edge, Set); err != nil {
t.Error(err) t.Error(err)
} }
var p types.Posting var p types.Posting
...@@ -246,8 +246,8 @@ func TestAddMutation_Value(t *testing.T) { ...@@ -246,8 +246,8 @@ func TestAddMutation_Value(t *testing.T) {
} }
// The value made it to the posting list. Changing it now. // The value made it to the posting list. Changing it now.
triple.Value = 119 edge.Value = 119
if err := ol.AddMutation(triple, Set); err != nil { if err := ol.AddMutation(edge, Set); err != nil {
t.Error(err) t.Error(err)
} }
if ol.Length() != 1 { if ol.Length() != 1 {
......
...@@ -62,8 +62,8 @@ func TestPush(t *testing.T) { ...@@ -62,8 +62,8 @@ func TestPush(t *testing.T) {
} }
} }
func addTriple(t *testing.T, triple x.Triple, l *List) { func addEdge(t *testing.T, edge x.DirectedEdge, l *List) {
if err := l.AddMutation(triple, Set); err != nil { if err := l.AddMutation(edge, Set); err != nil {
t.Error(err) t.Error(err)
} }
} }
...@@ -82,27 +82,27 @@ func TestProcessTask(t *testing.T) { ...@@ -82,27 +82,27 @@ func TestProcessTask(t *testing.T) {
ms.Init(mdir) ms.Init(mdir)
Init(ps, ms) Init(ps, ms)
triple := x.Triple{ edge := x.DirectedEdge{
ValueId: 23, ValueId: 23,
Source: "author0", Source: "author0",
Timestamp: time.Now(), Timestamp: time.Now(),
} }
addTriple(t, triple, Get(Key(10, "friend"))) addEdge(t, edge, Get(Key(10, "friend")))
addTriple(t, triple, Get(Key(11, "friend"))) addEdge(t, edge, Get(Key(11, "friend")))
addTriple(t, triple, Get(Key(12, "friend"))) addEdge(t, edge, Get(Key(12, "friend")))
triple.ValueId = 25 edge.ValueId = 25
addTriple(t, triple, Get(Key(12, "friend"))) addEdge(t, edge, Get(Key(12, "friend")))
triple.ValueId = 26 edge.ValueId = 26
addTriple(t, triple, Get(Key(12, "friend"))) addEdge(t, edge, Get(Key(12, "friend")))
triple.ValueId = 31 edge.ValueId = 31
addTriple(t, triple, Get(Key(10, "friend"))) addEdge(t, edge, Get(Key(10, "friend")))
addTriple(t, triple, Get(Key(12, "friend"))) addEdge(t, edge, Get(Key(12, "friend")))
triple.Value = "photon" edge.Value = "photon"
addTriple(t, triple, Get(Key(12, "friend"))) addEdge(t, edge, Get(Key(12, "friend")))
query := NewQuery("friend", []uint64{10, 11, 12}) query := NewQuery("friend", []uint64{10, 11, 12})
result, err := ProcessTask(query) result, err := ProcessTask(query)
......
...@@ -41,7 +41,7 @@ func setErr(err *error, nerr error) { ...@@ -41,7 +41,7 @@ func setErr(err *error, nerr error) {
func populateList(key []byte) error { func populateList(key []byte) error {
pl := posting.Get(key) pl := posting.Get(key)
t := x.Triple{ t := x.DirectedEdge{
ValueId: 9, ValueId: 9,
Source: "query_test", Source: "query_test",
Timestamp: time.Now(), Timestamp: time.Now(),
...@@ -126,8 +126,8 @@ func NewStore(t *testing.T) string { ...@@ -126,8 +126,8 @@ func NewStore(t *testing.T) string {
return path return path
} }
func addTriple(t *testing.T, triple x.Triple, l *posting.List) { func addEdge(t *testing.T, edge x.DirectedEdge, l *posting.List) {
if err := l.AddMutation(triple, posting.Set); err != nil { if err := l.AddMutation(edge, posting.Set); err != nil {
t.Error(err) t.Error(err)
} }
} }
...@@ -179,47 +179,47 @@ func TestProcessGraph(t *testing.T) { ...@@ -179,47 +179,47 @@ func TestProcessGraph(t *testing.T) {
// So, user we're interested in has uid: 1. // So, user we're interested in has uid: 1.
// She has 4 friends: 23, 24, 25, 31, and 101 // She has 4 friends: 23, 24, 25, 31, and 101
triple := x.Triple{ edge := x.DirectedEdge{
ValueId: 23, ValueId: 23,
Source: "testing", Source: "testing",
Timestamp: time.Now(), Timestamp: time.Now(),
} }
addTriple(t, triple, posting.Get(posting.Key(1, "friend"))) addEdge(t, edge, posting.Get(posting.Key(1, "friend")))
triple.ValueId = 24 edge.ValueId = 24
addTriple(t, triple, posting.Get(posting.Key(1, "friend"))) addEdge(t, edge, posting.Get(posting.Key(1, "friend")))
triple.ValueId = 25 edge.ValueId = 25
addTriple(t, triple, posting.Get(posting.Key(1, "friend"))) addEdge(t, edge, posting.Get(posting.Key(1, "friend")))
triple.ValueId = 31 edge.ValueId = 31
addTriple(t, triple, posting.Get(posting.Key(1, "friend"))) addEdge(t, edge, posting.Get(posting.Key(1, "friend")))
triple.ValueId = 101 edge.ValueId = 101
addTriple(t, triple, posting.Get(posting.Key(1, "friend"))) addEdge(t, edge, posting.Get(posting.Key(1, "friend")))
// Now let's add a few properties for the main user. // Now let's add a few properties for the main user.
triple.Value = "Michonne" edge.Value = "Michonne"
addTriple(t, triple, posting.Get(posting.Key(1, "name"))) addEdge(t, edge, posting.Get(posting.Key(1, "name")))
triple.Value = "female" edge.Value = "female"
addTriple(t, triple, posting.Get(posting.Key(1, "gender"))) addEdge(t, edge, posting.Get(posting.Key(1, "gender")))
triple.Value = "alive" edge.Value = "alive"
addTriple(t, triple, posting.Get(posting.Key(1, "status"))) addEdge(t, edge, posting.Get(posting.Key(1, "status")))
// Now let's add a name for each of the friends, except 101. // Now let's add a name for each of the friends, except 101.
triple.Value = "Rick Grimes" edge.Value = "Rick Grimes"
addTriple(t, triple, posting.Get(posting.Key(23, "name"))) addEdge(t, edge, posting.Get(posting.Key(23, "name")))
triple.Value = "Glenn Rhee" edge.Value = "Glenn Rhee"
addTriple(t, triple, posting.Get(posting.Key(24, "name"))) addEdge(t, edge, posting.Get(posting.Key(24, "name")))
triple.Value = "Daryl Dixon" edge.Value = "Daryl Dixon"
addTriple(t, triple, posting.Get(posting.Key(25, "name"))) addEdge(t, edge, posting.Get(posting.Key(25, "name")))
triple.Value = "Andrea" edge.Value = "Andrea"
addTriple(t, triple, posting.Get(posting.Key(31, "name"))) addEdge(t, edge, posting.Get(posting.Key(31, "name")))
// Alright. Now we have everything set up. Let's create the query. // Alright. Now we have everything set up. Let's create the query.
sg, err := NewGraph(1, "") sg, err := NewGraph(1, "")
......
...@@ -82,12 +82,12 @@ var testNQuads = []struct { ...@@ -82,12 +82,12 @@ var testNQuads = []struct {
}, },
}, },
{ {
input: `<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://purl.org/dc/terms/title> "N-Triples"@en-US .`, input: `<http://www.w3.org/2001/sw/RDFCore/nedges/> <http://purl.org/dc/terms/title> "N-Edges"@en-US .`,
nq: NQuad{ nq: NQuad{
Subject: "http://www.w3.org/2001/sw/RDFCore/ntriples/", Subject: "http://www.w3.org/2001/sw/RDFCore/nedges/",
Predicate: "http://purl.org/dc/terms/title", Predicate: "http://purl.org/dc/terms/title",
ObjectId: "", ObjectId: "",
ObjectValue: "N-Triples", ObjectValue: "N-Edges",
Language: "en-US", Language: "en-US",
}, },
}, },
......
...@@ -56,7 +56,7 @@ func allocateNew(xid string) (uid uint64, rerr error) { ...@@ -56,7 +56,7 @@ func allocateNew(xid string) (uid uint64, rerr error) {
} }
// Uid hasn't been assigned yet. // Uid hasn't been assigned yet.
t := x.Triple{ t := x.DirectedEdge{
Value: xid, // not txid Value: xid, // not txid
Source: "_assigner_", Source: "_assigner_",
Timestamp: time.Now(), Timestamp: time.Now(),
...@@ -92,7 +92,7 @@ func GetOrAssign(xid string) (uid uint64, rerr error) { ...@@ -92,7 +92,7 @@ func GetOrAssign(xid string) (uid uint64, rerr error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
t := x.Triple{ t := x.DirectedEdge{
ValueId: uid, ValueId: uid,
Source: "_assigner_", Source: "_assigner_",
Timestamp: time.Now(), Timestamp: time.Now(),
......
...@@ -28,7 +28,7 @@ type Status struct { ...@@ -28,7 +28,7 @@ type Status struct {
Message string `json:"message"` Message string `json:"message"`
} }
type Triple struct { type DirectedEdge struct {
Entity uint64 Entity uint64
EntityEid string EntityEid string
Attribute string Attribute string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment