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
2c50dfff
Commit
2c50dfff
authored
8 years ago
by
Manish R Jain
Browse files
Options
Downloads
Plain Diff
Merge pull request #68 from dgraph-io/dmuts
Bug Fix: Parse RDFs with _uid_:0xid
parents
8fdb25d4
bd9f12a7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
rdf/parse.go
+1
-2
1 addition, 2 deletions
rdf/parse.go
rdf/parse_test.go
+35
-0
35 additions, 0 deletions
rdf/parse_test.go
rdf/state.go
+41
-7
41 additions, 7 deletions
rdf/state.go
server/main.go
+7
-5
7 additions, 5 deletions
server/main.go
with
84 additions
and
14 deletions
rdf/parse.go
+
1
−
2
View file @
2c50dfff
...
...
@@ -69,8 +69,7 @@ func (nq NQuad) ToEdge() (result x.DirectedEdge, rerr error) {
}
func
toUid
(
xid
string
,
xidToUid
map
[
string
]
uint64
)
(
uid
uint64
,
rerr
error
)
{
id
,
present
:=
xidToUid
[
xid
]
if
present
{
if
id
,
present
:=
xidToUid
[
xid
];
present
{
return
id
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
rdf/parse_test.go
+
35
−
0
View file @
2c50dfff
...
...
@@ -44,6 +44,33 @@ var testNQuads = []struct {
ObjectValue
:
nil
,
},
},
{
input
:
`_uid_:0x01 <predicate> <object_id> .`
,
nq
:
NQuad
{
Subject
:
"_uid_:0x01"
,
Predicate
:
"predicate"
,
ObjectId
:
"object_id"
,
ObjectValue
:
nil
,
},
},
{
input
:
`<some_subject_id> <predicate> _uid_:0x01 .`
,
nq
:
NQuad
{
Subject
:
"some_subject_id"
,
Predicate
:
"predicate"
,
ObjectId
:
"_uid_:0x01"
,
ObjectValue
:
nil
,
},
},
{
input
:
`_uid_:0x01 <predicate> _uid_:0x02 .`
,
nq
:
NQuad
{
Subject
:
"_uid_:0x01"
,
Predicate
:
"predicate"
,
ObjectId
:
"_uid_:0x02"
,
ObjectValue
:
nil
,
},
},
{
input
:
`_:alice <follows> _:bob0 .`
,
nq
:
NQuad
{
...
...
@@ -106,6 +133,14 @@ var testNQuads = []struct {
input
:
"_:alice knows ."
,
hasErr
:
true
,
},
{
input
:
"_uid_: 0x01 <knows> <something> ."
,
hasErr
:
true
,
},
{
input
:
"<alice> <knows> _uid_: 0x01 ."
,
hasErr
:
true
,
},
{
input
:
`_:alice "knows" stuff .`
,
hasErr
:
true
,
...
...
This diff is collapsed.
Click to expand it.
rdf/state.go
+
41
−
7
View file @
2c50dfff
...
...
@@ -19,6 +19,9 @@
package
rdf
import
(
"strconv"
"strings"
"github.com/dgraph-io/dgraph/lex"
"github.com/dgraph-io/dgraph/x"
)
...
...
@@ -120,19 +123,38 @@ func lexUntilClosing(l *lex.Lexer, styp lex.ItemType,
return
l
.
Errorf
(
"Invalid character %v found for itemType: %v"
,
r
,
styp
)
}
func
lexUidNode
(
l
*
lex
.
Lexer
,
styp
lex
.
ItemType
,
sfn
lex
.
StateFn
)
lex
.
StateFn
{
l
.
AcceptUntil
(
isSpace
)
r
:=
l
.
Peek
()
if
r
==
lex
.
EOF
{
return
l
.
Errorf
(
"Unexpected end of uid subject"
)
}
in
:=
l
.
Input
[
l
.
Start
:
l
.
Pos
]
if
!
strings
.
HasPrefix
(
in
,
"_uid_:"
)
{
return
l
.
Errorf
(
"Expected _uid_: Found: %v"
,
l
.
Input
[
l
.
Start
:
l
.
Pos
])
}
if
_
,
err
:=
strconv
.
ParseUint
(
in
[
6
:
],
0
,
64
);
err
!=
nil
{
return
l
.
Errorf
(
"Unable to convert '%v' to UID"
,
in
[
6
:
])
}
if
isSpace
(
r
)
{
l
.
Emit
(
styp
)
return
sfn
}
return
l
.
Errorf
(
"Invalid character %v found for UID node itemType: %v"
,
r
,
styp
)
}
// Assumes that the current rune is '_'.
func
lexBlankNode
(
l
*
lex
.
Lexer
,
styp
lex
.
ItemType
,
sfn
lex
.
StateFn
)
lex
.
StateFn
{
r
:=
l
.
Next
()
if
r
!=
':'
{
return
l
.
Errorf
(
"Invalid input RDF Blank Node found at pos: %v"
,
r
)
}
// RDF Blank Node.
// TODO: At some point do checkings based on the guidelines. For now,
// just accept everything until space.
l
.
AcceptUntil
(
isSpace
)
r
=
l
.
Peek
()
r
:
=
l
.
Peek
()
if
r
==
lex
.
EOF
{
return
l
.
Errorf
(
"Unexpected end of subject"
)
}
...
...
@@ -152,7 +174,13 @@ func lexSubject(l *lex.Lexer) lex.StateFn {
if
r
==
'_'
{
l
.
Depth
+=
1
return
lexBlankNode
(
l
,
itemSubject
,
lexText
)
r
=
l
.
Next
()
if
r
==
'u'
{
return
lexUidNode
(
l
,
itemSubject
,
lexText
)
}
else
if
r
==
':'
{
return
lexBlankNode
(
l
,
itemSubject
,
lexText
)
}
// else go to error
}
return
l
.
Errorf
(
"Invalid character during lexSubject: %v"
,
r
)
...
...
@@ -239,7 +267,13 @@ func lexObject(l *lex.Lexer) lex.StateFn {
}
if
r
==
'_'
{
l
.
Depth
+=
1
return
lexBlankNode
(
l
,
itemObject
,
lexText
)
r
=
l
.
Next
()
if
r
==
'u'
{
return
lexUidNode
(
l
,
itemObject
,
lexText
)
}
else
if
r
==
':'
{
return
lexBlankNode
(
l
,
itemObject
,
lexText
)
}
}
if
r
==
'"'
{
l
.
Ignore
()
...
...
This diff is collapsed.
Click to expand it.
server/main.go
+
7
−
5
View file @
2c50dfff
...
...
@@ -80,16 +80,18 @@ func mutationHandler(mu *gql.Mutation) error {
xidToUid
:=
make
(
map
[
string
]
uint64
)
for
_
,
nq
:=
range
nquads
{
if
!
strings
.
HasPrefix
(
"_uid_:"
,
nq
.
Subject
)
{
if
!
strings
.
HasPrefix
(
nq
.
Subject
,
"_uid_:"
)
{
xidToUid
[
nq
.
Subject
]
=
0
}
if
!
strings
.
HasPrefix
(
"_uid_:"
,
nq
.
ObjectId
)
{
if
len
(
nq
.
ObjectId
)
>
0
&&
!
strings
.
HasPrefix
(
nq
.
ObjectId
,
"_uid_:"
)
{
xidToUid
[
nq
.
ObjectId
]
=
0
}
}
if
err
:=
worker
.
GetOrAssignUidsOverNetwork
(
&
xidToUid
);
err
!=
nil
{
glog
.
WithError
(
err
)
.
Error
(
"GetOrAssignUidsOverNetwork"
)
return
err
if
len
(
xidToUid
)
>
0
{
if
err
:=
worker
.
GetOrAssignUidsOverNetwork
(
&
xidToUid
);
err
!=
nil
{
glog
.
WithError
(
err
)
.
Error
(
"GetOrAssignUidsOverNetwork"
)
return
err
}
}
var
edges
[]
x
.
DirectedEdge
...
...
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