(v *NormalizeVisitor)
| 27 | } |
| 28 | |
| 29 | func (expr *CoalesceExpr) normalize(v *NormalizeVisitor) TypedExpr { |
| 30 | // This normalization checks whether COALESCE can be simplified |
| 31 | // based on constant expressions at the start of the COALESCE |
| 32 | // argument list. All known-null constant arguments are simply |
| 33 | // removed, and any known-nonnull constant argument before |
| 34 | // non-constant argument cause the entire COALESCE expression to |
| 35 | // collapse to that argument. |
| 36 | last := len(expr.Exprs) - 1 |
| 37 | for i := range expr.Exprs { |
| 38 | subExpr := expr.TypedExprAt(i) |
| 39 | |
| 40 | if i == last { |
| 41 | return subExpr |
| 42 | } |
| 43 | |
| 44 | if !v.isConst(subExpr) { |
| 45 | exprCopy := *expr |
| 46 | exprCopy.Exprs = expr.Exprs[i:] |
| 47 | return &exprCopy |
| 48 | } |
| 49 | |
| 50 | val, err := subExpr.Eval(v.ctx) |
| 51 | if err != nil { |
| 52 | v.err = err |
| 53 | return expr |
| 54 | } |
| 55 | |
| 56 | if val != DNull { |
| 57 | return subExpr |
| 58 | } |
| 59 | } |
| 60 | return expr |
| 61 | } |
| 62 | |
| 63 | func (expr *IfExpr) normalize(v *NormalizeVisitor) TypedExpr { |
| 64 | if v.isConst(expr.Cond) { |
nothing calls this directly
no test coverage detected