From b103dff04ff0eab1717eb39f3ce029865ad39894 Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 10 Oct 2019 12:25:03 +0800 Subject: [PATCH] =?UTF-8?q?planner:=20fix=20some=20window=20specific=20che?= =?UTF-8?q?ck=20bug=20for=20window=20function.=20(#12=E2=80=A6=20(#12405)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- planner/core/logical_plan_builder.go | 5 ++++- planner/core/logical_plan_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index bb8ff92354dc5..5af50afbc8983 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -3359,7 +3359,10 @@ func (b *PlanBuilder) checkOriginWindowSpecs(funcs []*ast.WindowFuncExpr, orderB if end.Type == ast.Preceding && end.UnBounded { return ErrWindowFrameEndIllegal.GenWithStackByArgs(getWindowName(spec.Name.O)) } - if start.Type == ast.Following && end.Type == ast.Preceding { + if start.Type == ast.Following && (end.Type == ast.Preceding || end.Type == ast.CurrentRow) { + return ErrWindowFrameIllegal.GenWithStackByArgs(getWindowName(spec.Name.O)) + } + if (start.Type == ast.Following || start.Type == ast.CurrentRow) && end.Type == ast.Preceding { return ErrWindowFrameIllegal.GenWithStackByArgs(getWindowName(spec.Name.O)) } diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index 90197777feabd..5fa597798e51b 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -2486,6 +2486,18 @@ func (s *testPlanSuite) TestWindowFunction(c *C) { sql: "SELECT NTH_VALUE(fieldA, -1) OVER (w1 PARTITION BY fieldB ORDER BY fieldB , fieldA ) AS 'ntile', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) as temp WINDOW w1 AS ( ORDER BY fieldB ASC, fieldA DESC )", result: "[planner:1210]Incorrect arguments to nth_value", }, + { + sql: "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN 1 FOLLOWING AND CURRENT ROW )", + result: "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", + }, + { + sql: "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN CURRENT ROW AND 1 PRECEDING )", + result: "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", + }, + { + sql: "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN 1 FOLLOWING AND 1 PRECEDING )", + result: "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", + }, // Test issue 11943 { sql: "SELECT ROW_NUMBER() OVER (partition by b) + a FROM t",