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

Function parseDirective

schema/parse.go:42–82  ·  view source on GitHub ↗
(it *lex.ItemIterator, schema *pb.SchemaUpdate, t types.TypeID)

Source from the content-addressed store, hash-verified

40}
41
42func parseDirective(it *lex.ItemIterator, schema *pb.SchemaUpdate, t types.TypeID) error {
43 it.Next()
44 next := it.Item()
45 if next.Typ != itemText {
46 return next.Errorf("Missing directive name")
47 }
48 switch next.Val {
49 case "reverse":
50 if t != types.UidID {
51 return next.Errorf("Cannot reverse for non-UID type")
52 }
53 schema.Directive = pb.SchemaUpdate_REVERSE
54 case "index":
55 tokenizer, vectorSpecs, err := parseIndexDirective(it, schema.Predicate, t)
56 if err != nil {
57 return err
58 }
59 schema.Directive = pb.SchemaUpdate_INDEX
60 schema.Tokenizer = tokenizer
61 schema.IndexSpecs = vectorSpecs
62 case "count":
63 schema.Count = true
64 case "upsert":
65 schema.Upsert = true
66 case "unique":
67 schema.Unique = true
68 case "noconflict":
69 schema.NoConflict = true
70 case "lang":
71 if t != types.StringID || schema.List {
72 return next.Errorf("@lang directive can only be specified for string type."+
73 " Got: [%v] for attr: [%v]", t.Name(), schema.Predicate)
74 }
75 schema.Lang = true
76 default:
77 return next.Errorf("Invalid index specification")
78 }
79 it.Next()
80
81 return nil
82}
83
84func parseScalarPair(it *lex.ItemIterator, predicate string, ns uint64) (*pb.SchemaUpdate, error) {
85 it.Next()

Callers 1

parseScalarPairFunction · 0.70

Calls 5

parseIndexDirectiveFunction · 0.85
ItemMethod · 0.80
NameMethod · 0.65
NextMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected