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

Function verifyUniqueWithinMutation

edgraph/server.go:2443–2480  ·  view source on GitHub ↗
(qc *queryContext)

Source from the content-addressed store, hash-verified

2441}
2442
2443func verifyUniqueWithinMutation(qc *queryContext) error {
2444 if len(qc.uniqueVars) == 0 {
2445 return nil
2446 }
2447
2448 for i := range qc.uniqueVars {
2449 gmuIndex, rdfIndex := decodeIndex(i)
2450 // handles cases where the mutation was pruned in updateMutations
2451 if gmuIndex >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex] == nil || rdfIndex >= uint32(len(qc.gmuList[gmuIndex].Set)) {
2452 continue
2453 }
2454 pred1 := qc.gmuList[gmuIndex].Set[rdfIndex]
2455 if pred1.ObjectValue == nil {
2456 continue
2457 }
2458 pred1Value := dql.TypeValFrom(pred1.ObjectValue).Value
2459 for j := range qc.uniqueVars {
2460 if i == j {
2461 continue
2462 }
2463 gmuIndex2, rdfIndex2 := decodeIndex(j)
2464 // check for the second predicate, which could also have been pruned
2465 if gmuIndex2 >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex2] == nil || rdfIndex2 >= uint32(len(qc.gmuList[gmuIndex2].Set)) {
2466 continue
2467 }
2468 pred2 := qc.gmuList[gmuIndex2].Set[rdfIndex2]
2469 if pred2.ObjectValue == nil {
2470 continue
2471 }
2472 if pred2.Predicate == pred1.Predicate && dql.TypeValFrom(pred2.ObjectValue).Value == pred1Value &&
2473 pred2.Subject != pred1.Subject {
2474 return errors.Errorf("could not insert duplicate value [%v] for predicate [%v]",
2475 pred1Value, pred1.Predicate)
2476 }
2477 }
2478 }
2479 return nil
2480}
2481
2482func isUpsertCondTrue(qc *queryContext, gmuIndex int) bool {
2483 condVar := qc.condVars[gmuIndex]

Callers 2

doMutateMethod · 0.85

Calls 3

TypeValFromFunction · 0.92
decodeIndexFunction · 0.85
ErrorfMethod · 0.45