Skip to content
Snippets Groups Projects
Commit 7be0e39c authored by Pawan Rawal's avatar Pawan Rawal
Browse files

Adding xid field to graph.Node and passing pointer to destination node in

preTraverse()
parent 5a62b48a
No related branches found
No related tags found
No related merge requests found
...@@ -53,9 +53,10 @@ func (*Value) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } ...@@ -53,9 +53,10 @@ func (*Value) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
type Node struct { type Node struct {
Uid uint64 `protobuf:"varint,1,opt,name=uid" json:"uid,omitempty"` Uid uint64 `protobuf:"varint,1,opt,name=uid" json:"uid,omitempty"`
Attribute string `protobuf:"bytes,2,opt,name=attribute" json:"attribute,omitempty"` Xid string `protobuf:"bytes,2,opt,name=xid" json:"xid,omitempty"`
Properties map[string]*Value `protobuf:"bytes,3,rep,name=properties" json:"properties,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` Attribute string `protobuf:"bytes,3,opt,name=attribute" json:"attribute,omitempty"`
Children []*Node `protobuf:"bytes,4,rep,name=children" json:"children,omitempty"` Properties map[string]*Value `protobuf:"bytes,4,rep,name=properties" json:"properties,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
Children []*Node `protobuf:"bytes,5,rep,name=children" json:"children,omitempty"`
} }
func (m *Node) Reset() { *m = Node{} } func (m *Node) Reset() { *m = Node{} }
...@@ -155,22 +156,22 @@ var _DGraph_serviceDesc = grpc.ServiceDesc{ ...@@ -155,22 +156,22 @@ var _DGraph_serviceDesc = grpc.ServiceDesc{
} }
var fileDescriptor0 = []byte{ var fileDescriptor0 = []byte{
// 266 bytes of a gzipped FileDescriptorProto // 272 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x5c, 0x90, 0x41, 0x4b, 0xc3, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0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 0xd6, 0xe8, 0x27, 0xfd, 0xbd, 0x69, 0x4b, 0x35, 0x55, 0xb1, 0xe0, 0xd5, 0x68, 0xb0, 0x2a, 0x37, 0xe2, 0xf4, 0x01, 0xf6, 0xfe, 0xf9, 0xd8,
0x4c, 0x40, 0x7c, 0xdb, 0x27, 0xd9, 0x64, 0x94, 0x4d, 0x9c, 0x14, 0x3f, 0x2e, 0xd7, 0xe8, 0x76, 0xa0, 0xef, 0xf4, 0x7b, 0xb8, 0x85, 0x98, 0x80, 0xf8, 0xb4, 0x67, 0x73, 0xf8, 0x28, 0x9b, 0x38,
0x74, 0xe3, 0x65, 0x57, 0x10, 0xde, 0x3f, 0x5a, 0x84, 0x17, 0x20, 0x5e, 0x6d, 0x3e, 0xb8, 0xef, 0x2b, 0xae, 0x42, 0xae, 0xa5, 0xeb, 0xd1, 0x95, 0x97, 0x5d, 0x40, 0x78, 0x7b, 0x6f, 0x25, 0x3c,
0x76, 0x5d, 0x8a, 0xd3, 0xa1, 0x8d, 0x64, 0xa7, 0x08, 0x39, 0xed, 0xeb, 0xdf, 0x00, 0x00, 0x00, 0x03, 0xf1, 0x6c, 0x1b, 0xc3, 0x5d, 0x37, 0xeb, 0x7a, 0x9d, 0x0e, 0x63, 0x24, 0x5b, 0x45, 0xc8,
0xff, 0xff, 0x2c, 0xc9, 0x79, 0xe9, 0x84, 0x01, 0x00, 0x00, 0xfd, 0x5f, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0xb8, 0x91, 0x31, 0x0d, 0x96, 0x01, 0x00, 0x00,
} }
...@@ -18,7 +18,8 @@ message Value { ...@@ -18,7 +18,8 @@ message Value {
message Node { message Node {
uint64 uid = 1; uint64 uid = 1;
string attribute = 2; string xid = 2;
map<string, Value> properties = 3; string attribute = 3;
repeated Node children = 4; // Each node can have multiple children map<string, Value> properties = 4;
repeated Node children = 5; // Each node can have multiple children
} }
...@@ -271,18 +271,19 @@ func indexOf(uid uint64, q *task.Query) int { ...@@ -271,18 +271,19 @@ func indexOf(uid uint64, q *task.Query) int {
} }
// This method gets the values and children for a subgraph. // This method gets the values and children for a subgraph.
func preTraverse(uid uint64, g *SubGraph) (map[string]*graph.Value, []*graph.Node, error) { func (g *SubGraph) preTraverse(uid uint64, dst *graph.Node) error {
values := make(map[string]*graph.Value) properties := make(map[string]*graph.Value)
var children []*graph.Node var children []*graph.Node
for _, predChild := range g.Children { // We go through all predicate children of the subgraph.
ro := flatbuffers.GetUOffsetT(predChild.result) for _, pc := range g.Children {
ro := flatbuffers.GetUOffsetT(pc.result)
r := new(task.Result) r := new(task.Result)
r.Init(predChild.result, ro) r.Init(pc.result, ro)
uo := flatbuffers.GetUOffsetT(predChild.query) uo := flatbuffers.GetUOffsetT(pc.query)
q := new(task.Query) q := new(task.Query)
q.Init(predChild.query, uo) q.Init(pc.query, uo)
idx := indexOf(uid, q) idx := indexOf(uid, q)
...@@ -290,15 +291,15 @@ func preTraverse(uid uint64, g *SubGraph) (map[string]*graph.Value, []*graph.Nod ...@@ -290,15 +291,15 @@ func preTraverse(uid uint64, g *SubGraph) (map[string]*graph.Value, []*graph.Nod
glog.WithFields(logrus.Fields{ glog.WithFields(logrus.Fields{
"uid": uid, "uid": uid,
"attribute": g.Attr, "attribute": g.Attr,
"childAttribute": predChild.Attr, "childAttribute": pc.Attr,
}).Fatal("Attribute with uid not found in child Query uids") }).Fatal("Attribute with uid not found in child Query uids")
return values, children, fmt.Errorf("Attribute with uid not found") return fmt.Errorf("Attribute with uid not found")
} }
var ul task.UidList var ul task.UidList
var tv task.Value var tv task.Value
if ok := r.Uidmatrix(&ul, idx); !ok { if ok := r.Uidmatrix(&ul, idx); !ok {
return values, children, fmt.Errorf("While parsing UidList") return fmt.Errorf("While parsing UidList")
} }
if ul.UidsLength() > 0 { if ul.UidsLength() > 0 {
...@@ -306,28 +307,25 @@ func preTraverse(uid uint64, g *SubGraph) (map[string]*graph.Value, []*graph.Nod ...@@ -306,28 +307,25 @@ func preTraverse(uid uint64, g *SubGraph) (map[string]*graph.Value, []*graph.Nod
// this predicate. // this predicate.
for i := 0; i < ul.UidsLength(); i++ { for i := 0; i < ul.UidsLength(); i++ {
uid := ul.Uids(i) uid := ul.Uids(i)
uidChild := new(graph.Node) uc := new(graph.Node)
uidChild.Attribute = predChild.Attr uc.Attribute = pc.Attr
uidChild.Uid = uid uc.Uid = uid
if rerr := pc.preTraverse(uid, uc); rerr != nil {
vals, ch, rerr := preTraverse(uid, predChild)
if rerr != nil {
x.Err(glog, rerr).Error("Error while traversal") x.Err(glog, rerr).Error("Error while traversal")
return values, children, rerr return rerr
} }
uidChild.Properties, uidChild.Children = vals, ch children = append(children, uc)
children = append(children, uidChild)
} }
} else { } else {
v := new(graph.Value) v := new(graph.Value)
if ok := r.Values(&tv, idx); !ok { if ok := r.Values(&tv, idx); !ok {
return values, children, fmt.Errorf("While parsing value") return fmt.Errorf("While parsing value")
} }
var ival interface{} var ival interface{}
if err := posting.ParseValue(&ival, tv.ValBytes()); err != nil { if err := posting.ParseValue(&ival, tv.ValBytes()); err != nil {
return values, children, err return err
} }
if ival == nil { if ival == nil {
...@@ -335,10 +333,14 @@ func preTraverse(uid uint64, g *SubGraph) (map[string]*graph.Value, []*graph.Nod ...@@ -335,10 +333,14 @@ func preTraverse(uid uint64, g *SubGraph) (map[string]*graph.Value, []*graph.Nod
} }
v.Binary = []byte(ival.(string)) v.Binary = []byte(ival.(string))
values[predChild.Attr] = v properties[pc.Attr] = v
} }
} }
return values, children, nil if val, ok := properties["xid"]; ok {
dst.Xid = string(val.Binary)
}
dst.Properties, dst.Children = properties, children
return nil
} }
// This method transforms the predicate based subgraph to an // This method transforms the predicate based subgraph to an
...@@ -358,8 +360,7 @@ func (g *SubGraph) ToProtocolBuffer(l *Latency) (n *graph.Node, rerr error) { ...@@ -358,8 +360,7 @@ func (g *SubGraph) ToProtocolBuffer(l *Latency) (n *graph.Node, rerr error) {
r.Uidmatrix(&ul, 0) r.Uidmatrix(&ul, 0)
n.Uid = ul.Uids(0) n.Uid = ul.Uids(0)
n.Properties, n.Children, rerr = preTraverse(n.Uid, g) if rerr = g.preTraverse(n.Uid, n); rerr != nil {
if rerr != nil {
x.Err(glog, rerr).Error("Error while traversal") x.Err(glog, rerr).Error("Error while traversal")
return n, rerr return n, rerr
} }
......
...@@ -184,6 +184,9 @@ func populateGraph(t *testing.T) (string, *store.Store) { ...@@ -184,6 +184,9 @@ func populateGraph(t *testing.T) (string, *store.Store) {
edge.Value = "Andrea" edge.Value = "Andrea"
addEdge(t, edge, posting.GetOrCreate(posting.Key(31, "name"), ps)) addEdge(t, edge, posting.GetOrCreate(posting.Key(31, "name"), ps))
edge.Value = "mich"
addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "xid"), ps))
return dir, ps return dir, ps
} }
...@@ -327,6 +330,7 @@ func TestToProtocolBuffer(t *testing.T) { ...@@ -327,6 +330,7 @@ func TestToProtocolBuffer(t *testing.T) {
query := ` query := `
{ {
me(_uid_:0x01) { me(_uid_:0x01) {
xid
name name
gender gender
status status
...@@ -367,8 +371,11 @@ func TestToProtocolBuffer(t *testing.T) { ...@@ -367,8 +371,11 @@ func TestToProtocolBuffer(t *testing.T) {
if gr.Uid != 1 { if gr.Uid != 1 {
t.Errorf("Expected uid 1, Got: %v", gr.Uid) t.Errorf("Expected uid 1, Got: %v", gr.Uid)
} }
if len(gr.Properties) != 3 { if gr.Xid != "mich" {
t.Errorf("Expected values map to contain 3 properties, Got: %v", t.Errorf("Expected xid mich, Got: %v", gr.Xid)
}
if len(gr.Properties) != 4 {
t.Errorf("Expected values map to contain 4 properties, Got: %v",
len(gr.Properties)) len(gr.Properties))
} }
if string(gr.Properties["name"].Binary) != "Michonne" { if string(gr.Properties["name"].Binary) != "Michonne" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment