Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
dgraph
Commits
87e81038
Commit
87e81038
authored
8 years ago
by
Pawan Rawal
Browse files
Options
Downloads
Patches
Plain Diff
Adding some documentation and renaming variables.
parent
71d7ba2c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
query/query.go
+22
-20
22 additions, 20 deletions
query/query.go
with
22 additions
and
20 deletions
query/query.go
+
22
−
20
View file @
87e81038
...
...
@@ -253,13 +253,14 @@ func (g *SubGraph) ToJson(l *Latency) (js []byte, rerr error) {
return
json
.
Marshal
(
r
)
}
// Struct to retrieve values from flatbuffers, so that they can later be used
// to control the entity based protocol buffer subgraph.
type
result
struct
{
values
[][]
byte
uidmatrix
[][]
uint64
}
// This method take in a flatbuffer result, extracts values and uids from it
// and converts it to a protocol buffer result
// This method takes in a flatbuffer query and result extracts values.
func
extract
(
q
*
task
.
Query
,
r
*
task
.
Result
)
([]
uint64
,
*
result
,
error
)
{
re
:=
new
(
result
)
var
qu
[]
uint64
...
...
@@ -303,8 +304,8 @@ func extract(q *task.Query, r *task.Result) ([]uint64, *result, error) {
}
// Struct to store reference to the subgraph associated with a protocol buffer
// response
type
sg
r
eference
struct
{
//
graph
response
type
sg
R
eference
struct
{
uid
uint64
sg
*
SubGraph
}
...
...
@@ -315,7 +316,6 @@ func (g *SubGraph) ToProtocolBuffer(l *Latency) (gr *pb.GraphResponse,
rerr
error
)
{
gr
=
&
pb
.
GraphResponse
{}
gr
.
Attribute
=
g
.
Attr
if
len
(
g
.
query
)
==
0
{
return
gr
,
nil
}
...
...
@@ -330,21 +330,22 @@ func (g *SubGraph) ToProtocolBuffer(l *Latency) (gr *pb.GraphResponse,
_
,
result
,
err
:=
extract
(
q
,
r
)
if
err
!=
nil
{
x
.
Err
(
glog
,
err
)
.
Error
(
"Error while extracting query, result"
)
return
gr
,
err
}
re
:=
&
sgreference
{}
re
:=
&
sgReference
{}
// Storing reference to root node.
re
.
sg
=
g
// Stores the uid for the root node in the reference struct.
re
.
uid
=
result
.
uidmatrix
[
0
][
0
]
gr
.
Values
,
gr
.
Children
,
rerr
=
re
.
pretraverse
()
gr
.
Values
,
gr
.
Children
,
rerr
=
re
.
preTraverse
()
if
rerr
!=
nil
{
x
.
Err
(
glog
,
rerr
)
.
Error
(
"Error while traversal"
)
return
gr
,
rerr
}
l
.
ProtocolBuffer
=
time
.
Since
(
l
.
Start
)
-
l
.
Parsing
-
l
.
Processing
l
.
ProtocolBuffer
=
time
.
Since
(
l
.
Start
)
-
l
.
Parsing
-
l
.
Processing
return
gr
,
nil
}
...
...
@@ -366,9 +367,9 @@ func indexOf(uid uint64, uids []uint64) int {
}
// This method gets the values and children for a GraphResponse.
func
(
re
*
sg
r
eference
)
pre
t
raverse
()
(
map
[
string
]
*
pb
.
Value
,
func
(
re
*
sg
R
eference
)
pre
T
raverse
()
(
map
[
string
]
*
pb
.
Value
,
[]
*
pb
.
GraphResponse
,
error
)
{
vals
:=
make
(
map
[
string
]
*
pb
.
Value
)
val
ue
s
:=
make
(
map
[
string
]
*
pb
.
Value
)
var
children
[]
*
pb
.
GraphResponse
for
_
,
child
:=
range
re
.
sg
.
Children
{
...
...
@@ -383,7 +384,7 @@ func (re *sgreference) pretraverse() (map[string]*pb.Value,
query
,
result
,
err
:=
extract
(
q
,
r
)
if
err
!=
nil
{
x
.
Err
(
glog
,
err
)
.
Error
(
"Error while extracting query, result"
)
return
vals
,
children
,
fmt
.
Errorf
(
"While extracting query, result"
)
return
val
ue
s
,
children
,
fmt
.
Errorf
(
"While extracting query, result"
)
}
idx
:=
indexOf
(
re
.
uid
,
query
)
...
...
@@ -393,13 +394,14 @@ func (re *sgreference) pretraverse() (map[string]*pb.Value,
"attribute"
:
re
.
sg
.
Attr
,
"childAttribute"
:
child
.
Attr
,
})
.
Fatal
(
"Attribute with uid not found in child Query uids"
)
return
vals
,
children
,
fmt
.
Errorf
(
"Attribute with uid not found"
)
return
val
ue
s
,
children
,
fmt
.
Errorf
(
"Attribute with uid not found"
)
}
// This means the child is a leaf node hence we just extract its value.
if
len
(
child
.
Children
)
==
0
{
v
al
:=
new
(
pb
.
Value
)
v
al
.
Byte
=
result
.
values
[
idx
]
vals
[
child
.
Attr
]
=
v
al
v
:=
new
(
pb
.
Value
)
v
.
Byte
=
result
.
values
[
idx
]
val
ue
s
[
child
.
Attr
]
=
v
}
else
{
uids
:=
result
.
uidmatrix
[
idx
]
// We create as many predicate children as the number of uids.
...
...
@@ -407,14 +409,14 @@ func (re *sgreference) pretraverse() (map[string]*pb.Value,
predChild
:=
new
(
pb
.
GraphResponse
)
predChild
.
Attribute
=
child
.
Attr
ref
:=
new
(
sg
r
eference
)
ref
:=
new
(
sg
R
eference
)
ref
.
sg
=
child
ref
.
uid
=
uid
vals
,
ch
,
rerr
:=
ref
.
pre
t
raverse
()
vals
,
ch
,
rerr
:=
ref
.
pre
T
raverse
()
if
rerr
!=
nil
{
x
.
Err
(
glog
,
rerr
)
.
Error
(
"Error while traversal"
)
return
vals
,
children
,
rerr
return
val
ue
s
,
children
,
rerr
}
predChild
.
Values
,
predChild
.
Children
=
vals
,
ch
...
...
@@ -422,7 +424,7 @@ func (re *sgreference) pretraverse() (map[string]*pb.Value,
}
}
}
return
vals
,
children
,
nil
return
val
ue
s
,
children
,
nil
}
func
treeCopy
(
gq
*
gql
.
GraphQuery
,
sg
*
SubGraph
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment