()
| 214 | } |
| 215 | |
| 216 | func (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 | } |
no test coverage detected