How do I specify UID?

Hi,I have a problem with Pydgraph.I need to specify the Uid.But I found that the UID of the node I specified still seemed to conflict with the system generated.How is UID generated?

For example:
I set

 item = {
                'uid': '{}'.format('0x1'),
                'dgraph.type': 'Person',
                'name': 'Allen',
            }

In the Retal,They’re all searchable UID “0x1”

{
  all(func:uid(0x01)){
    uid
    name
  }
}
{
  all(func:uid(0x0001)){
    uid
    name
  }
}

Besides, the UID I set myself doesn’t seem to be accepted by dgraph.On a node that I didn’t specify, its UID could also be “0x1”

UIDs are generated by Zero. If you want to set your own UIDs, you could try the method provided here.

/assign?what=uids&num=100 This would allocate num uids and return a JSON map containing startId and endId , both inclusive. This id range can be safely assigned externally to new nodes during data ingestion.

Do I need to specify which Uids I want to customize? So how do I specify these Uids?
Can you give some examples?

Assuming the default setup (http port for zero is at 6080), this command will reserve a 100 uids for you:
http://localhost:6080/assign?what=uids&num=100

The response to this request might look something like this:

startId “115”
endId “214”

This means that the uids from 0x73 to 0xd6 are reserved for you. We can use one of the reserved UIDs as below. This was fired from ratel directly after reserving uids.

{
  set{
    <0x73> <name> "A reserved UID" .
  }
}

You can then query to confirm as below:
Query:

{
  query(func: uid(<0x73>)){
    uid
    name
  }
}

Response:

"data": {
    "query": [
      {
        "uid": "0x73",
        "name": "A reserved UID"
      }
    ]
  }

If I don’t specify the scope of the reservation,and I specified the UID “0x1”,What would generate a similar UID “0x1”?

You have to reserve the UID if you want to control it. AFAIK, I am not aware of any other procedure to consistently set UID.

Thank you,I’ll try it.

WIth dgraph v20.03.x, GraphQL layer in dgraph may use the uid 0x1 to store the GraphQL schema.

Could you tell me more about it?Or can you give some examples?Thanks!

I was saying that in 20.03.x versions, you may find the uid 0x1 to be already used. That doesn’t happen anymore in the latest 20.07.x versions. So, no need to worry about the uid 0x1 not being available anymore.