Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
c02a685d
Commit
c02a685d
authored
9 years ago
by
Manish R Jain
Browse files
Options
Downloads
Patches
Plain Diff
Fix channel blocking issue during GQL parsing. Allow '-' to be part of predicate name.
parent
0f905d99
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Dockerfile
+1
-1
1 addition, 1 deletion
Dockerfile
gql/parser.go
+28
-18
28 additions, 18 deletions
gql/parser.go
gql/parser_test.go
+21
-0
21 additions, 0 deletions
gql/parser_test.go
gql/state.go
+2
-2
2 additions, 2 deletions
gql/state.go
lex/lexer.go
+2
-2
2 additions, 2 deletions
lex/lexer.go
with
54 additions
and
23 deletions
Dockerfile
+
1
−
1
View file @
c02a685d
...
...
@@ -21,7 +21,7 @@ ENV LD_LIBRARY_PATH "/usr/local/lib"
# Install DGraph and update dependencies to right versions.
RUN
go get
-v
github.com/robfig/glock
&&
\
go get
-v
github.com/dgraph-io/dgraph/...
&&
\
glock
sync
github.com/dgraph-io/dgraph
&&
echo
"v0.1.
0
"
glock
sync
github.com/dgraph-io/dgraph
&&
echo
"v0.1.
1
"
# Run some tests, don't build an image if we're failing tests.
RUN
go
test
github.com/dgraph-io/dgraph/...
...
...
This diff is collapsed.
Click to expand it.
gql/parser.go
+
28
−
18
View file @
c02a685d
...
...
@@ -57,7 +57,9 @@ func Parse(input string) (sg *query.SubGraph, rerr error) {
return
nil
,
rerr
}
}
else
{
godeep
(
l
,
sg
)
if
err
:=
godeep
(
l
,
sg
);
err
!=
nil
{
return
sg
,
err
}
}
}
}
...
...
@@ -114,29 +116,37 @@ func getRoot(l *lex.Lexer) (sg *query.SubGraph, rerr error) {
return
query
.
NewGraph
(
uid
,
xid
)
}
func
godeep
(
l
*
lex
.
Lexer
,
sg
*
query
.
SubGraph
)
{
curp
:=
sg
// stores current pointer.
for
{
switch
item
:=
<-
l
.
Items
;
{
case
item
.
Typ
==
itemName
:
func
godeep
(
l
*
lex
.
Lexer
,
sg
*
query
.
SubGraph
)
error
{
curp
:=
sg
// Used to track current node, for nesting.
for
item
:=
range
l
.
Items
{
if
item
.
Typ
==
lex
.
ItemError
{
return
errors
.
New
(
item
.
Val
)
}
else
if
item
.
Typ
==
lex
.
ItemEOF
{
return
nil
}
else
if
item
.
Typ
==
itemName
{
child
:=
new
(
query
.
SubGraph
)
child
.
Attr
=
item
.
Val
sg
.
Children
=
append
(
sg
.
Children
,
child
)
curp
=
child
case
item
.
Typ
==
itemLeftCurl
:
godeep
(
l
,
curp
)
// recursive iteration
case
item
.
Typ
==
itemRightCurl
:
return
case
item
.
Typ
==
itemLeftRound
:
// absorb all these, we don't care right now.
for
{
item
=
<-
l
.
Items
if
item
.
Typ
==
itemRightRound
||
item
.
Typ
==
lex
.
ItemEOF
{
break
}
else
if
item
.
Typ
==
itemLeftCurl
{
if
err
:=
godeep
(
l
,
curp
);
err
!=
nil
{
return
err
}
}
else
if
item
.
Typ
==
itemRightCurl
{
return
nil
}
else
if
item
.
Typ
==
itemLeftRound
{
// absorb all these, we don't use them right now.
for
ti
:=
range
l
.
Items
{
if
ti
.
Typ
==
itemRightRound
||
ti
.
Typ
==
lex
.
ItemEOF
{
return
nil
}
}
default
:
// continue
}
}
return
nil
}
This diff is collapsed.
Click to expand it.
gql/parser_test.go
+
21
−
0
View file @
c02a685d
...
...
@@ -53,6 +53,7 @@ func TestParse(t *testing.T) {
}
if
len
(
sg
.
Children
)
!=
4
{
t
.
Errorf
(
"Expected 4 children. Got: %v"
,
len
(
sg
.
Children
))
return
}
if
err
:=
checkAttr
(
sg
.
Children
[
0
],
"friends"
);
err
!=
nil
{
t
.
Error
(
err
)
...
...
@@ -160,3 +161,23 @@ func TestParse_pass1(t *testing.T) {
t
.
Errorf
(
"Expected 0. Got: %v"
,
len
(
sg
.
Children
))
}
}
func
TestParse_block
(
t
*
testing
.
T
)
{
query
:=
`
{
root(_uid_: 0x0a) {
type.object.name.es-419
}
}
`
sg
,
err
:=
Parse
(
query
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
len
(
sg
.
Children
)
!=
1
{
t
.
Errorf
(
"Expected 1. Got: %v"
,
len
(
sg
.
Children
))
}
if
err
:=
checkAttr
(
sg
.
Children
[
0
],
"type.object.name.es-419"
);
err
!=
nil
{
t
.
Error
(
err
)
}
}
This diff is collapsed.
Click to expand it.
gql/state.go
+
2
−
2
View file @
c02a685d
...
...
@@ -28,7 +28,7 @@ const (
itemLeftCurl
// left curly bracket
itemRightCurl
// right curly bracket
itemComment
// comment
itemName
// names
itemName
//
[9]
names
itemOpType
// operation type
itemString
// quoted string
itemLeftRound
// left round bracket
...
...
@@ -234,7 +234,7 @@ func isNameSuffix(r rune) bool {
if
r
>=
'0'
&&
r
<=
'9'
{
return
true
}
if
r
==
'.'
{
if
r
==
'.'
||
r
==
'-'
{
// Use by freebase.
return
true
}
return
false
...
...
This diff is collapsed.
Click to expand it.
lex/lexer.go
+
2
−
2
View file @
c02a685d
...
...
@@ -50,7 +50,7 @@ func (i item) String() string {
case
0
:
return
"EOF"
}
return
fmt
.
Sprintf
(
"[%v] %q"
,
i
.
Typ
,
i
.
Val
)
return
fmt
.
Sprintf
(
"
lex.Item
[%v] %q"
,
i
.
Typ
,
i
.
Val
)
}
type
Lexer
struct
{
...
...
@@ -68,7 +68,7 @@ type Lexer struct {
func
NewLexer
(
input
string
)
*
Lexer
{
l
:=
&
Lexer
{
Input
:
input
,
Items
:
make
(
chan
item
),
Items
:
make
(
chan
item
,
100
),
}
return
l
}
...
...
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