evalDatumsCmp evaluates Datums (slice of Datum) using the provided sub-operator type (ANY/SOME, ALL) and its CmpOp with the left Datum. It returns the result of the ANY/SOME/ALL predicate. A NULL result is returned if there exists a NULL element and: ANY/SOME: no comparisons evaluate to true ALL: n
( ctx *EvalContext, op, subOp ComparisonOperator, fn *CmpOp, left Datum, right Datums, )
| 2438 | // evalArrayCmp would be called with: |
| 2439 | // evalDatumsCmp(ctx, LT, Any, CmpOp(LT, leftType, rightParamType), leftDatum, rightArray.Array). |
| 2440 | func evalDatumsCmp( |
| 2441 | ctx *EvalContext, op, subOp ComparisonOperator, fn *CmpOp, left Datum, right Datums, |
| 2442 | ) (Datum, error) { |
| 2443 | all := op == All |
| 2444 | any := !all |
| 2445 | sawNull := false |
| 2446 | for _, elem := range right { |
| 2447 | if elem == DNull { |
| 2448 | sawNull = true |
| 2449 | continue |
| 2450 | } |
| 2451 | |
| 2452 | _, newLeft, newRight, _, not := foldComparisonExpr(subOp, left, elem) |
| 2453 | d, err := fn.Fn(ctx, newLeft.(Datum), newRight.(Datum)) |
| 2454 | if err != nil { |
| 2455 | return nil, err |
| 2456 | } |
| 2457 | if d == DNull { |
| 2458 | sawNull = true |
| 2459 | continue |
| 2460 | } |
| 2461 | |
| 2462 | b := d.(*DBool) |
| 2463 | res := *b != DBool(not) |
| 2464 | if any && res { |
| 2465 | return DBoolTrue, nil |
| 2466 | } else if all && !res { |
| 2467 | return DBoolFalse, nil |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | if sawNull { |
| 2472 | // If the right-hand array contains any null elements and no [false,true] |
| 2473 | // comparison result is obtained, the result of [ALL,ANY] will be null. |
| 2474 | return DNull, nil |
| 2475 | } |
| 2476 | |
| 2477 | if all { |
| 2478 | // ALL are true && !sawNull |
| 2479 | return DBoolTrue, nil |
| 2480 | } |
| 2481 | // ANY is false && !sawNull |
| 2482 | return DBoolFalse, nil |
| 2483 | } |
| 2484 | |
| 2485 | //// MatchLikeEscape matches 'unescaped' with 'pattern' using custom escape character 'escape' which |
| 2486 | //// must be either empty (which disables the escape mechanism) or a single unicode character. |
no test coverage detected
searching dependent graphs…