Does xid attribute needs to be defined in the type for bulk loader to xid --store_xids flag

Officecial docs says

*--store_xids: Generate a xid edge for each node. It will store the XIDs (The identifier / Blank-nodes) in an attribute named xid in the entity itself. It is useful if you gonna use External IDs.*

Does xid attribute needs to be defined in my type for bulk loader to store xid when --store_xids flag was used?

Below is my typical type. Since we want to use bulk loader, should we define an explicit xid attribute as part of the type declaration?

type Course {
    codeId: CourseTcode!
    eventId: Int!
    timestamp: DateTime! @search
    student: Student
    xid: String! @search(by: [hash])
}

Bulk loader is not made to be used consecutively back to back. Hence all data is treated as one source of blank nodes and no need for xid. From your other posts I see you are trying to script it to run multiple times with multiple files and probably expect the data to be interlinked, but are finding out it is not because of this xid issue.

And if you are going to use xid you need to put it on every GraphQL type and use @dgraph directive to map it to a single predicate, otherwise you will have a <type>.xid predicate for every type which will not work for bulk or live loading as those require ONE global predicate on every type.

Are you saying, no need have an explicit xid attribute in my type?

type Course {
    codeId: CourseTcode!
    eventId: Int!
    timestamp: DateTime! @search
    student: Student
    xid: String! @search(by: [hash])    <---I should remove this?
}

Either remove it and it will not be available to the GraphQLAPI and you may need to adjust the DQL indexes for the predicate it creates for you, or change it to:

type Course {
    codeId: CourseTcode!
    eventId: Int!
    timestamp: DateTime! @search
    student: Student
    xid: String! @search(by: [hash]) @dgraph(pred: "xid") # <-- copy on every type
}
  • I don’t see the xid when I queried for my type

    {
      test(func: has(Course.student), first:5) {
       Course.timestamp
       xid
      }
    }
    
  • The RDF data file I up loaded

     <_:my.org/Student/10101/Course/201/Event/1> <Course.eventId> "1" .
     <_:my.org/Student/10101/Course/201/Event/1> <Course.timestamp> "2022-01-01T00:00:02.298240" .
     <_:my.org/Student/10101/Course/201/Event/1> <Course.student> 
     <_:my.org/Student/10101> .
     <_:my.org/Student/10101/Course/201/Event/1> <Course.codeId> 
     <_:my.org/CourseTcode/201> .
    
  • The type I wrote earlier was a DQL type…like below

     type Course {
      codeId: CourseTcode!
      eventId: Int!
      timestamp: DateTime! @search
      student: Student
      xid: String! @search(by: [hash])
     }
    
  • It’s corresponding GraphQL type (like below) was exactly what you wrote were suggesting.

     type Course {
      codeId: CourseTcode!
      eventId: Int!
      timestamp: DateTime! @search
      student: Student
      xid: String! @search(by: [hash]) @dgraph(pred: "xid") 
     }
    

Sorry, I was confused because this is not DQL schema syntax and if it was it would not map to the GraphQL schema you posted and I modified.

Back to the OP though…

If you did have this then this query should return something:

# DQL
query {
  n(func: has(xid), first: 1) {
    uid
    xid
  }
}
  • If bulk uploader was used, my query doesn’t get xid
    – Bulk load command

     dgraph bulk -f ${files_in_ready_state} -s ${schemaFile} --format=rdf --xidmap xid --store_xids --map_shards=6 --reduce_shards=3 --zero=dgraph-dgraph-zero:5080
    

    – Query

     {
      test(func: has(Course.student), first:5) {
       Course.timestamp
       xid
      }
     }
    

    – DQL type

     type Course {
      codeId: CourseTcode!
      eventId: Int!
      timestamp: DateTime! @search
      student: Student
      xid: String! @search(by: [hash])
     }
    
  • On other hand; I can get xid without issue if upsert was used with Live uploader!
    – Live up load command

     dgraph live --files /coldstart/upload/pending_predicates --schema /coldstart/upload/rdf_schema/my_schema.rdf --alpha host.docker.internal:9080 --zero host.docker.internal:5080 --format=rdf --upsertPredicate "xid" -b 3000