From fb31829bbec45a2721c628f0a38f3fcd9fa7729e Mon Sep 17 00:00:00 2001 From: kanchairen Date: Tue, 30 Jul 2019 13:46:12 +0800 Subject: [PATCH] window function: function name of ErrWindowInvalidWindowFuncUse should be lowercase.(#11508) --- planner/core/expression_rewriter.go | 2 +- planner/core/logical_plan_builder.go | 2 +- planner/core/logical_plan_test.go | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/planner/core/expression_rewriter.go b/planner/core/expression_rewriter.go index 4a79a68e3f7d9..b19901f9031a9 100644 --- a/planner/core/expression_rewriter.go +++ b/planner/core/expression_rewriter.go @@ -323,7 +323,7 @@ func (er *expressionRewriter) Enter(inNode ast.Node) (ast.Node, bool) { index, ok = er.windowMap[v] } if !ok { - er.err = ErrWindowInvalidWindowFuncUse.GenWithStackByArgs(v.F) + er.err = ErrWindowInvalidWindowFuncUse.GenWithStackByArgs(strings.ToLower(v.F)) return inNode, true } er.ctxStack = append(er.ctxStack, er.schema.Columns[index]) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index bc2087d1190b3..d434c8fecec19 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1241,7 +1241,7 @@ func (a *havingWindowAndOrderbyExprResolver) Leave(n ast.Node) (node ast.Node, o case *ast.WindowFuncExpr: a.inWindowFunc = false if a.curClause == havingClause { - a.err = ErrWindowInvalidWindowFuncUse.GenWithStackByArgs(v.F) + a.err = ErrWindowInvalidWindowFuncUse.GenWithStackByArgs(strings.ToLower(v.F)) return node, false } if a.curClause == orderByClause { diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index fac77b8e6c31a..910f4c8a26044 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -2411,6 +2411,14 @@ func (s *testPlanSuite) TestWindowFunction(c *C) { sql: "delete from t order by (sum(a) over())", result: "[planner:3593]You cannot use the window function 'sum' in this context.'", }, + { + sql: "delete from t order by (SUM(a) over())", + result: "[planner:3593]You cannot use the window function 'sum' in this context.'", + }, + { + sql: "SELECT * from t having ROW_NUMBER() over()", + result: "[planner:3593]You cannot use the window function 'row_number' in this context.'", + }, { // The best execution order should be (a,c), (a, b, c), (a, b), (), it requires only 2 sort operations. sql: "select sum(a) over (partition by a order by b), sum(b) over (order by a, b, c), sum(c) over(partition by a order by c), sum(d) over() from t",