How to specify uid in rdf files when using dgraph bulk load?

hello everyone,

when I use test.rdf:

<0x1> <name> "alpha" .
<0x1> <friend> <0x2> .
<0x2> <name> "beta" .

test.schema:

friend: uid @reverse @count .
name:string @index(term, exact) .

use bulk loader:
dgraph bulk -r test.rdf -s test.schema

and I export the database and found that uid changes!!!

curl localhost:8080/admin/export

<_:uid1> <name> "alpha"^^<xs:string> .
<_:uid2711> <name> "beta"^^<xs:string> .
<_:uid1> <friend> <_:uid2711>

Could someone help me? Thanks a lot!!!

The export data need not contain the uid you have specified.

After import you can verify that the uid are used by doing a query on an uid in ratel.

2 Likes

I tried to query with:

{
  fd(func: eq(name,"alpha"))
 {
    uid
    name
    friend
   {
     uid
     name
    }
 }
}

the result is

  "data": {
    "fd": [
      {
        "uid": "0x1",
        "name": "alpha",
        "friend": [
          {
            "uid": "0x2711",
            "name": "beta"
          }
        ]
      }
    ]
  }

“beta” uid is 0x2711, not 0x2.

As @smantha said, UIDs are not preserved in the export RDF data. You can use an external ID that you control in your data if you need a persistent ID.

1 Like

thanks! And I also want to confirm that, dgraph live can specify UID using “assign”, but dgraph bulk cannot, right?

Just for future visits to this thread. As I understand this is not true anymore and exports now preserve UIDs. From Dgraph v1.1.0 release notes:

Export data contains UID literals instead of blank nodes. Using Live Loader or Bulk Loader to load exported data will result in the same UIDs as the original database. (#3004, #3045) To preserve the previous behavior, set the --new_uids flag in the live or bulk loader. (1827787)