MCPcopy Create free account
hub / github.com/cel-expr/cel-go / applyQualifiers

Function applyQualifiers

interpreter/attributes.go:1490–1542  ·  view source on GitHub ↗
(vars Activation, obj any, qualifiers []Qualifier)

Source from the content-addressed store, hash-verified

1488}
1489
1490func applyQualifiers(vars Activation, obj any, qualifiers []Qualifier) (any, bool, error) {
1491 // Early return if there's nothing to apply
1492 if len(qualifiers) == 0 {
1493 return obj, false, nil
1494 }
1495
1496 // Test for an optional select that's on an empty value.
1497 optObj, isOpt := obj.(*types.Optional)
1498 if isOpt {
1499 if !optObj.HasValue() {
1500 return optObj, false, nil
1501 }
1502 obj = optObj.GetValue()
1503 }
1504
1505 frame, hasFrame := vars.(*ExecutionFrame)
1506 var err error
1507 for _, qual := range qualifiers {
1508 var qualObj any
1509 isOpt = isOpt || qual.IsOptional()
1510 if isOpt {
1511 var present bool
1512 qualObj, present, err = qual.QualifyIfPresent(vars, obj, false)
1513 if hasFrame {
1514 if costs := frame.CostTracker(); costs != nil &&
1515 (present || err != nil || costs.ModelVersion() >= 1) {
1516 costs.Qualify(qual.ID())
1517 }
1518 }
1519 if err != nil {
1520 return nil, false, err
1521 }
1522 if !present {
1523 // We return optional none here with a presence of 'false' as the layers
1524 // above will attempt to call types.OptionalOf() on a present value if any
1525 // of the qualifiers is optional.
1526 return types.OptionalNone, false, nil
1527 }
1528 } else {
1529 qualObj, err = qual.Qualify(vars, obj)
1530 if hasFrame {
1531 if costs := frame.CostTracker(); costs != nil {
1532 costs.Qualify(qual.ID())
1533 }
1534 }
1535 if err != nil {
1536 return nil, false, err
1537 }
1538 }
1539 obj = qualObj
1540 }
1541 return obj, isOpt, nil
1542}
1543
1544// attrQualify performs a qualification using the result of an attribute evaluation.
1545func attrQualify(fac AttributeFactory, vars Activation, obj any, qualAttr Attribute) (any, error) {

Callers 3

ResolveMethod · 0.85
ResolveMethod · 0.85
ResolveMethod · 0.85

Calls 8

HasValueMethod · 0.80
GetValueMethod · 0.80
CostTrackerMethod · 0.80
ModelVersionMethod · 0.80
IsOptionalMethod · 0.65
QualifyIfPresentMethod · 0.65
QualifyMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected