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


#1

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!!!


How to insert new data using a bulk loader without losing old data
#2

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.


#3

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.


(Daniel Mai) #4

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.


#5

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