Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2934: export with uid #3004

Merged
merged 4 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dgraph/cmd/live/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func handleError(err error) {
fmt.Printf("Server is overloaded. Will retry after %s.", dur.Round(time.Minute))
time.Sleep(dur)
case err != y.ErrAborted && err != y.ErrConflict:
fmt.Printf("Error while mutating %v\n", s.Message())
fmt.Printf("Error while mutating: %v\n", s.Message())
}
}

Expand Down
10 changes: 5 additions & 5 deletions systest/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ func TestLoaderXidmap(t *testing.T) {
t.Fatalf("While trying to sort exported file: %v", err)
}

expected = `<_:uid1> <age> "13" .
<_:uid1> <friend> <_:uid2711> .
<_:uid1> <location> "Wonderland" .
<_:uid1> <name> "Alice" .
<_:uid2711> <name> "Bob" .
expected = `<0x1> <age> "13" .
<0x1> <friend> <0x2711> .
<0x1> <location> "Wonderland" .
<0x1> <name> "Alice" .
<0x2711> <name> "Bob" .
`

if string(out) != expected {
Expand Down
7 changes: 5 additions & 2 deletions worker/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ var predNonSpecialChars = unicode.RangeTable{
},
}

// UIDs like 0x1 look weird but 64-bit ones like 0x0000000000000001 are too long.
var uidFmtStr = "<0x%x>"

func toRDF(pl *posting.List, prefix string, readTs uint64) (*bpb.KVList, error) {
var buf bytes.Buffer

err := pl.Iterate(readTs, 0, func(p *pb.Posting) error {
buf.WriteString(prefix)
if p.PostingType == pb.Posting_REF {
buf.WriteString(fmt.Sprintf("<_:uid%x>", p.Uid))
buf.WriteString(fmt.Sprintf(uidFmtStr, p.Uid))

} else {
// Value posting
Expand Down Expand Up @@ -313,7 +316,7 @@ func export(ctx context.Context, in *pb.ExportRequest) error {
return toSchema(pk.Attr, update)

case pk.IsData():
prefix := fmt.Sprintf("<_:uid%x> <%s> ", pk.Uid, pk.Attr)
prefix := fmt.Sprintf(uidFmtStr+" <%s> ", pk.Uid, pk.Attr)
pl, err := posting.ReadPostingList(key, itr)
if err != nil {
return nil, err
Expand Down
20 changes: 10 additions & 10 deletions worker/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,37 +149,37 @@ func TestExport(t *testing.T) {
for scanner.Scan() {
nq, err := rdf.Parse(scanner.Text())
require.NoError(t, err)
require.Contains(t, []string{"_:uid1", "_:uid2", "_:uid3", "_:uid4", "_:uid5"}, nq.Subject)
require.Contains(t, []string{"0x1", "0x2", "0x3", "0x4", "0x5"}, nq.Subject)
if nq.ObjectValue != nil {
switch nq.Subject {
case "_:uid1", "_:uid2":
case "0x1", "0x2":
require.Equal(t, &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "pho\ton"}},
nq.ObjectValue)
case "_:uid3":
case "0x3":
require.Equal(t, &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "First Line\nSecondLine"}},
nq.ObjectValue)
case "_:uid4":
case "_:uid5":
require.Equal(t, `<_:uid5> <name> "" .`, scanner.Text())
case "0x4":
case "0x5":
require.Equal(t, `<0x5> <name> "" .`, scanner.Text())
default:
t.Errorf("Unexpected subject: %v", nq.Subject)
}
if nq.Subject == "_:uid1" || nq.Subject == "_:uid2" {
if nq.Subject == "_:uid1" || nq.Subject == "0x2" {
require.Equal(t, &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "pho\ton"}},
nq.ObjectValue)
}
}

// The only objectId we set was uid 5.
if nq.ObjectId != "" {
require.Equal(t, "_:uid5", nq.ObjectId)
require.Equal(t, "0x5", nq.ObjectId)
}
// Test lang.
if nq.Subject == "_:uid2" && nq.Predicate == "name" {
if nq.Subject == "0x2" && nq.Predicate == "name" {
require.Equal(t, "en", nq.Lang)
}
// Test facets.
if nq.Subject == "_:uid4" {
if nq.Subject == "0x4" {
require.Equal(t, "age", nq.Facets[0].Key)
require.Equal(t, "close", nq.Facets[1].Key)
require.Equal(t, "game", nq.Facets[2].Key)
Expand Down