NormalizeExpr normalizes a typed expression, simplifying where possible, but guaranteeing that the result of evaluating the expression is unchanged and that resulting expression tree is still well-typed. Example normalizations: (a) -> a a = 1 + 1 -> a = 2 a + 1 = 2
(typedExpr TypedExpr)
| 675 | // a BETWEEN b AND c -> (a >= b) AND (a <= c) |
| 676 | // a NOT BETWEEN b AND c -> (a < b) OR (a > c) |
| 677 | func (ctx *EvalContext) NormalizeExpr(typedExpr TypedExpr) (TypedExpr, error) { |
| 678 | v := MakeNormalizeVisitor(ctx) |
| 679 | expr, _ := WalkExpr(&v, typedExpr) |
| 680 | if v.err != nil { |
| 681 | return nil, v.err |
| 682 | } |
| 683 | return expr.(TypedExpr), nil |
| 684 | } |
| 685 | |
| 686 | // NormalizeVisitor supports the execution of NormalizeExpr. |
| 687 | type NormalizeVisitor struct { |