VisitPost implements the Visitor interface.
(expr Expr)
| 719 | |
| 720 | // VisitPost implements the Visitor interface. |
| 721 | func (v *NormalizeVisitor) VisitPost(expr Expr) Expr { |
| 722 | if v.err != nil { |
| 723 | return expr |
| 724 | } |
| 725 | // We don't propagate errors during this step because errors might involve a |
| 726 | // branch of code that isn't traversed by normal execution (for example, |
| 727 | // IF(2 = 2, 1, 1 / 0)). |
| 728 | |
| 729 | // Normalize expressions that know how to normalize themselves. |
| 730 | if normalizable, ok := expr.(normalizableExpr); ok { |
| 731 | expr = normalizable.normalize(v) |
| 732 | if v.err != nil { |
| 733 | return expr |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | // Evaluate all constant expressions. |
| 738 | if v.isConst(expr) { |
| 739 | value, err := expr.(TypedExpr).Eval(v.ctx) |
| 740 | if err != nil { |
| 741 | // Ignore any errors here (e.g. division by zero), so they can happen |
| 742 | // during execution where they are correctly handled. Note that in some |
| 743 | // cases we might not even get an error (if this particular expression |
| 744 | // does not get evaluated when the query runs, e.g. it's inside a CASE). |
| 745 | return expr |
| 746 | } |
| 747 | if value == DNull { |
| 748 | // We don't want to return an expression that has a different type; cast |
| 749 | // the NULL if necessary. |
| 750 | return ReType(DNull, expr.(TypedExpr).ResolvedType()) |
| 751 | } |
| 752 | return value |
| 753 | } |
| 754 | |
| 755 | return expr |
| 756 | } |
| 757 | |
| 758 | func (v *NormalizeVisitor) isConst(expr Expr) bool { |
| 759 | return v.fastIsConstVisitor.run(expr) |
nothing calls this directly
no test coverage detected