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

Bug Fix: Parse RDFs when _uid_:0xid is provided.

parent 8fdb25d4
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
......@@ -44,6 +44,15 @@ var testNQuads = []struct {
ObjectValue: nil,
},
},
{
input: `_uid_:0x01 <predicate> <object_id> .`,
nq: NQuad{
Subject: "_uid_:0x01",
Predicate: "predicate",
ObjectId: "object_id",
ObjectValue: nil,
},
},
{
input: `_:alice <follows> _:bob0 .`,
nq: NQuad{
......@@ -106,6 +115,10 @@ var testNQuads = []struct {
input: "_:alice knows .",
hasErr: true,
},
{
input: "_uid_: 0x01 <knows> <something> .",
hasErr: true,
},
{
input: `_:alice "knows" stuff .`,
hasErr: true,
......
......@@ -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)
......
......@@ -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
......
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