MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / GetPredicateValues

Function GetPredicateValues

testutil/backup.go:137–187  ·  view source on GitHub ↗

GetPredicateValues reads the specified p directory and returns the values for the given attribute in a map.

(pdir, attr string, readTs uint64)

Source from the content-addressed store, hash-verified

135// GetPredicateValues reads the specified p directory and returns the values for the given
136// attribute in a map.
137func GetPredicateValues(pdir, attr string, readTs uint64) (map[string]string, error) {
138 db, err := openDgraph(pdir)
139 if err != nil {
140 return nil, err
141 }
142 defer db.Close()
143
144 values := make(map[string]string)
145
146 txn := db.NewTransactionAt(readTs, false)
147 defer txn.Discard()
148 itr := txn.NewIterator(badger.DefaultIteratorOptions)
149 defer itr.Close()
150
151 for itr.Rewind(); itr.Valid(); itr.Next() {
152 item := itr.Item()
153 pk, err := x.Parse(item.Key())
154 x.Check(err)
155 switch {
156 case pk.Attr != attr:
157 continue
158 case !pk.IsData():
159 continue
160 }
161
162 pl, err := posting.ReadPostingList(item.Key(), itr)
163 if err != nil {
164 return nil, err
165 }
166
167 err = pl.Iterate(readTs, 0, func(p *pb.Posting) error {
168 vID := types.TypeID(p.ValType)
169 src := types.ValueForType(vID)
170 src.Value = p.Value
171 str, err := types.Convert(src, types.StringID)
172 if err != nil {
173 return err
174 }
175 value := str.Value.(string)
176 values[fmt.Sprintf("%#x", pk.Uid)] = value
177
178 return nil
179 })
180
181 if err != nil {
182 return nil, err
183 }
184 }
185
186 return values, err
187}
188
189type dataType int
190

Callers 4

runRestoreFunction · 0.92
runRestoreFunction · 0.92
runRestoreFunction · 0.92
runRestoreFunction · 0.92

Calls 15

ParseFunction · 0.92
CheckFunction · 0.92
ReadPostingListFunction · 0.92
TypeIDTypeAlias · 0.92
ValueForTypeFunction · 0.92
ConvertFunction · 0.92
openDgraphFunction · 0.85
NewIteratorMethod · 0.80
ValidMethod · 0.80
ItemMethod · 0.80
IsDataMethod · 0.80
CloseMethod · 0.65

Tested by 4

runRestoreFunction · 0.74
runRestoreFunction · 0.74
runRestoreFunction · 0.74
runRestoreFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…