(initial *schema.ParsedSchema, opt *BulkOptions, state *state)
| 29 | } |
| 30 | |
| 31 | func newSchemaStore(initial *schema.ParsedSchema, opt *BulkOptions, state *state) *schemaStore { |
| 32 | if opt == nil { |
| 33 | log.Fatalf("Cannot create schema store with nil options.") |
| 34 | } |
| 35 | |
| 36 | s := &schemaStore{ |
| 37 | schemaMap: map[string]*pb.SchemaUpdate{}, |
| 38 | state: state, |
| 39 | } |
| 40 | |
| 41 | // Initialize only for the default namespace. Initialization for other namespaces will be done |
| 42 | // whenever we see data for a new namespace. |
| 43 | s.checkAndSetInitialSchema(x.RootNamespace) |
| 44 | |
| 45 | s.types = initial.Types |
| 46 | // This is from the schema read from the schema file. |
| 47 | for _, sch := range initial.Preds { |
| 48 | p := sch.Predicate |
| 49 | sch.Predicate = "" // Predicate is stored in the (badger) key, so not needed in the value. |
| 50 | if _, ok := s.schemaMap[p]; ok { |
| 51 | fmt.Printf("Predicate %q already exists in schema\n", p) |
| 52 | continue |
| 53 | } |
| 54 | s.checkAndSetInitialSchema(x.ParseNamespace(p)) |
| 55 | s.schemaMap[p] = sch |
| 56 | } |
| 57 | |
| 58 | return s |
| 59 | } |
| 60 | |
| 61 | func (s *schemaStore) getSchema(pred string) *pb.SchemaUpdate { |
| 62 | s.RLock() |
no test coverage detected