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

Method evaluate

worker/task.go:2508–2595  ·  view source on GitHub ↗
(cp countParams, out *pb.Result)

Source from the content-addressed store, hash-verified

2506}
2507
2508func (qs *queryState) evaluate(cp countParams, out *pb.Result) error {
2509 countl := cp.counts[0]
2510 var counth int64
2511 if cp.fn == between {
2512 counth = cp.counts[1]
2513 }
2514 var illegal bool
2515 switch cp.fn {
2516 case "eq":
2517 illegal = countl <= 0
2518 case "lt":
2519 illegal = countl <= 1
2520 case "le":
2521 illegal = countl <= 0
2522 case "gt":
2523 illegal = countl < 0
2524 case "ge":
2525 illegal = countl <= 0
2526 case "between":
2527 illegal = countl <= 0 || counth <= 0
2528 default:
2529 x.AssertTruef(false, "unhandled count comparison fn: %v", cp.fn)
2530 }
2531 if illegal {
2532 return errors.Errorf("count(predicate) cannot be used to search for " +
2533 "negative counts (nonsensical) or zero counts (not tracked).")
2534 }
2535
2536 countKey := x.CountKey(cp.attr, uint32(countl), cp.reverse)
2537 if cp.fn == "eq" {
2538 pl, err := qs.cache.GetUids(countKey)
2539 if err != nil {
2540 return err
2541 }
2542 uids, err := pl.Uids(posting.ListOptions{ReadTs: cp.readTs})
2543 if err != nil {
2544 return err
2545 }
2546 out.UidMatrix = append(out.UidMatrix, uids)
2547 return nil
2548 }
2549
2550 switch cp.fn {
2551 case "lt":
2552 countl--
2553 case "gt":
2554 countl++
2555 }
2556
2557 x.AssertTrue(countl >= 1)
2558 countKey = x.CountKey(cp.attr, uint32(countl), cp.reverse)
2559
2560 txn := pstore.NewTransactionAt(cp.readTs, false)
2561 defer txn.Discard()
2562
2563 pk := x.ParsedKey{Attr: cp.attr}
2564 itOpt := badger.DefaultIteratorOptions
2565 itOpt.PrefetchValues = false

Callers 1

Calls 14

CountPrefixMethod · 0.95
AssertTruefFunction · 0.92
CountKeyFunction · 0.92
AssertTrueFunction · 0.92
ParseFunction · 0.92
NewIteratorMethod · 0.80
SeekMethod · 0.80
ValidMethod · 0.80
ItemMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.45
GetUidsMethod · 0.45

Tested by

no test coverage detected