MCPcopy
hub / github.com/dgraph-io/dgraph / toRDF

Method toRDF

worker/export.go:216–284  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

214}
215
216func (e *exporter) toRDF() (*bpb.KVList, error) {
217 bp := new(bytes.Buffer)
218
219 prefix := fmt.Sprintf(uidFmtStrRdf+" <%s> ", e.uid, e.attr)
220 err := e.pl.Iterate(e.readTs, 0, func(p *pb.Posting) error {
221 if p.PostingType == pb.Posting_REF {
222 fmt.Fprint(bp, prefix)
223 fmt.Fprintf(bp, uidFmtStrRdf, p.Uid)
224 } else {
225 val := types.Val{Tid: types.TypeID(p.ValType), Value: p.Value}
226 str, err := valToStr(val)
227 if err != nil {
228 glog.Errorf("Ignoring error: %+v\n", err)
229 return nil
230 }
231 fmt.Fprint(bp, prefix)
232 fmt.Fprintf(bp, "%s", escapedString(str))
233
234 tid := types.TypeID(p.ValType)
235 if p.PostingType == pb.Posting_VALUE_LANG {
236 fmt.Fprint(bp, "@"+string(p.LangTag))
237 } else if tid != types.DefaultID {
238 rdfType, ok := rdfTypeMap[tid]
239 x.AssertTruef(ok, "Didn't find RDF type for dgraph type: %+v", tid.Name())
240 fmt.Fprint(bp, "^^<"+rdfType+">")
241 }
242 }
243 // Use label for storing namespace.
244 fmt.Fprintf(bp, " <%#x>", e.namespace)
245
246 // Facets.
247 if len(p.Facets) != 0 {
248 fmt.Fprint(bp, " (")
249 for i, fct := range p.Facets {
250 if i != 0 {
251 fmt.Fprint(bp, ",")
252 }
253 fmt.Fprint(bp, fct.Key+"=")
254
255 str, err := facetToString(fct)
256 if err != nil {
257 glog.Errorf("Ignoring error: %+v", err)
258 return nil
259 }
260
261 tid, err := facets.TypeIDFor(fct)
262 if err != nil {
263 glog.Errorf("Error getting type id from facet %#v: %v", fct, err)
264 continue
265 }
266
267 if tid == types.StringID {
268 str = escapedString(str)
269 }
270 fmt.Fprint(bp, str)
271 }
272 fmt.Fprint(bp, ")")
273 }

Callers 1

ToExportKvListFunction · 0.95

Calls 10

TypeIDTypeAlias · 0.92
AssertTruefFunction · 0.92
TypeIDForFunction · 0.92
valToStrFunction · 0.85
escapedStringFunction · 0.85
facetToStringFunction · 0.85
listWrapFunction · 0.85
NameMethod · 0.65
IterateMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected