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

Method handleCompareFunction

worker/task.go:1358–1524  ·  view source on GitHub ↗
(ctx context.Context, arg funcArgs)

Source from the content-addressed store, hash-verified

1356}
1357
1358func (qs *queryState) handleCompareFunction(ctx context.Context, arg funcArgs) error {
1359 span := trace.SpanFromContext(ctx)
1360 stop := x.SpanTimer(span, "handleCompareFunction")
1361 defer stop()
1362 span.AddEvent("Processing UIDs", trace.WithAttributes(
1363 attribute.Int64("uid_count", int64(arg.srcFn.n)),
1364 attribute.String("srcFn", x.SafeUTF8(fmt.Sprintf("%+v", arg.srcFn)))))
1365
1366 attr := arg.q.Attr
1367 span.AddEvent("Function information", trace.WithAttributes(
1368 attribute.String("attr", attr),
1369 attribute.String("fname", arg.srcFn.fname)))
1370 tokenizer, err := pickTokenizer(ctx, attr, arg.srcFn.fname)
1371 if err != nil {
1372 return err
1373 }
1374
1375 // Only if the tokenizer that we used IsLossy
1376 // then we need to fetch and compare the actual values.
1377 span.AddEvent("Tokenizer details", trace.WithAttributes(
1378 attribute.String("tokenizer", tokenizer.Name()),
1379 attribute.Bool("is_lossy", tokenizer.IsLossy())))
1380
1381 if !tokenizer.IsLossy() {
1382 return nil
1383 }
1384
1385 // Need to evaluate inequality for entries in the first bucket.
1386 typ, err := schema.State().TypeOf(attr)
1387 if err != nil || !typ.IsScalar() {
1388 return errors.Errorf("Attribute not scalar: %s %v", x.ParseAttr(attr), typ)
1389 }
1390
1391 x.AssertTrue(len(arg.out.UidMatrix) > 0)
1392 isList := schema.State().IsList(attr)
1393 lang := langForFunc(arg.q.Langs)
1394
1395 filterRow := func(row int, compareFunc func(types.Val) bool) error {
1396 select {
1397 case <-ctx.Done():
1398 return ctx.Err()
1399 default:
1400 }
1401
1402 var filterErr error
1403 algo.ApplyFilter(arg.out.UidMatrix[row], func(uid uint64, i int) bool {
1404 switch lang {
1405 case "":
1406 if isList {
1407 pl, err := qs.cache.Get(x.DataKey(attr, uid))
1408 if err != nil {
1409 filterErr = err
1410 return false
1411 }
1412 svs, err := pl.AllUntaggedValues(arg.q.ReadTs)
1413 if err != nil {
1414 if err != posting.ErrNoValue {
1415 filterErr = err

Callers 1

helpProcessTaskMethod · 0.95

Calls 15

SpanTimerFunction · 0.92
SafeUTF8Function · 0.92
StateFunction · 0.92
ParseAttrFunction · 0.92
AssertTrueFunction · 0.92
ApplyFilterFunction · 0.92
DataKeyFunction · 0.92
ConvertFunction · 0.92
CompareValsFunction · 0.92
CompareBetweenFunction · 0.92
pickTokenizerFunction · 0.85
langForFuncFunction · 0.85

Tested by

no test coverage detected