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

Function sortWithIndex

worker/sort.go:189–365  ·  view source on GitHub ↗
(ctx context.Context, ts *pb.SortMessage)

Source from the content-addressed store, hash-verified

187}
188
189func sortWithIndex(ctx context.Context, ts *pb.SortMessage) *sortresult {
190 if ctx.Err() != nil {
191 return resultWithError(ctx.Err())
192 }
193
194 span := trace.SpanFromContext(ctx)
195 span.SetAttributes(attribute.String("sortWithIndex", "true"))
196
197 n := len(ts.UidMatrix)
198 out := make([]intersectedList, n)
199 values := make([][]types.Val, 0, n) // Values corresponding to uids in the uid matrix.
200 for i := range n {
201 // offsets[i] is the offset for i-th posting list. It gets decremented as we
202 // iterate over buckets.
203 out[i].offset = int(ts.Offset)
204 out[i].ulist = &pb.List{}
205 out[i].skippedUids = &pb.List{}
206 out[i].uset = map[uint64]struct{}{}
207 }
208
209 order := ts.Order[0]
210 typ, err := schema.State().TypeOf(order.Attr)
211 if err != nil {
212 return resultWithError(errors.Errorf("Attribute %s not defined in schema", order.Attr))
213 }
214
215 // Get the tokenizers and choose the corresponding one.
216 if !schema.State().IsIndexed(ctx, order.Attr) {
217 return resultWithError(errors.Errorf("Attribute %s is not indexed.", order.Attr))
218 }
219
220 tokenizers := schema.State().Tokenizer(ctx, order.Attr)
221 var tokenizer tok.Tokenizer
222 for _, t := range tokenizers {
223 // Get the first sortable index.
224 if t.IsSortable() {
225 tokenizer = t
226 break
227 }
228 }
229
230 if tokenizer == nil {
231 // String type can have multiple tokenizers, only one of which is
232 // sortable.
233 if typ == types.StringID {
234 return resultWithError(errors.Errorf(
235 "Attribute %s does not have exact index for sorting.", order.Attr))
236 }
237 // Other types just have one tokenizer, so if we didn't find a
238 // sortable tokenizer, then attribute isn't sortable.
239 return resultWithError(errors.Errorf("Attribute %s is not sortable.", order.Attr))
240 }
241
242 var prefix []byte
243 if len(order.Langs) > 0 {
244 // Only one language is allowed.
245 lang := order.Langs[0]
246 tokenizer = tok.GetTokenizerForLang(tokenizer, lang)

Callers 1

processSortFunction · 0.85

Calls 15

IdentifierMethod · 0.95
StateFunction · 0.92
GetTokenizerForLangFunction · 0.92
IndexKeyFunction · 0.92
ParseFunction · 0.92
AssertTrueFunction · 0.92
MinFunction · 0.92
resultWithErrorFunction · 0.85
intersectBucketFunction · 0.85
TypeOfMethod · 0.80
IsIndexedMethod · 0.80
TokenizerMethod · 0.80

Tested by

no test coverage detected