From ced79bd3b26780e79b52e15e2081be749fc69660 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Thu, 1 Aug 2019 11:20:25 +0800 Subject: [PATCH 1/3] fix window function ignore nulls bug --- planner/core/logical_plan_builder.go | 3 +++ planner/core/logical_plan_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index cd649ee2251cf..d7097867f9bbe 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -3218,6 +3218,9 @@ func (b *PlanBuilder) buildWindowFunctions(ctx context.Context, p LogicalPlan, g // Because of the grouped specification is different from it, we should especially check them before build window frame. func (b *PlanBuilder) checkOriginWindowSpecs(funcs []*ast.WindowFuncExpr, orderByItems []property.Item) error { for _, f := range funcs { + if f.IgnoreNull { + return ErrNotSupportedYet.GenWithStackByArgs("IGNORE NULLS") + } spec := f.Spec if spec.Frame == nil { continue diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index cd96dae5cf2ad..19ced12bd77d0 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -2403,6 +2403,11 @@ func (s *testPlanSuite) TestWindowFunction(c *C) { sql: "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a asc range between 1250951168 following AND 1250951168 preceding)", result: "[planner:3586]Window 'w1': frame start or end is negative, NULL or of non-integral type", }, + // Test issue 10556. + { + sql: "SELECT FIRST_VALUE(a) IGNORE NULLS OVER () FROM t", + result: "[planner:1235]This version of TiDB doesn't yet support 'IGNORE NULLS'", + }, } s.Parser.EnableWindowFunc(true) From a8c0570c8d89939ad2eaba34b527c5e27f650cd0 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Thu, 1 Aug 2019 11:45:55 +0800 Subject: [PATCH 2/3] add distinct and from_last check --- planner/core/logical_plan_builder.go | 6 ++++++ planner/core/logical_plan_test.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index d7097867f9bbe..3e68d8080b052 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -3221,6 +3221,12 @@ func (b *PlanBuilder) checkOriginWindowSpecs(funcs []*ast.WindowFuncExpr, orderB if f.IgnoreNull { return ErrNotSupportedYet.GenWithStackByArgs("IGNORE NULLS") } + if f.Distinct { + return ErrNotSupportedYet.GenWithStackByArgs("(DISTINCT ..)") + } + if f.FromLast { + return ErrNotSupportedYet.GenWithStackByArgs("FROM LAST") + } spec := f.Spec if spec.Frame == nil { continue diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index 19ced12bd77d0..f26d1a6722dd7 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -2408,6 +2408,18 @@ func (s *testPlanSuite) TestWindowFunction(c *C) { sql: "SELECT FIRST_VALUE(a) IGNORE NULLS OVER () FROM t", result: "[planner:1235]This version of TiDB doesn't yet support 'IGNORE NULLS'", }, + { + sql: "SELECT SUM(DISTINCT a) OVER () FROM t", + result: "[planner:1235]This version of TiDB doesn't yet support '(DISTINCT ..)'", + }, + { + sql: "SELECT NTH_VALUE(a, 1) FROM LAST over (partition by b order by b), a FROM t1;", + result: "[planner:1235]This version of TiDB doesn't yet support 'FROM LAST'", + }, + { + sql: "SELECT NTH_VALUE(a, 1) FROM LAST IGNORE NULLS over (partition by b order by b), a FROM t1", + result: "[planner:1235]This version of TiDB doesn't yet support 'IGNORE NULLS'", + }, } s.Parser.EnableWindowFunc(true) From 2307aa7a6174cf7471bc703390ba2f70bd9bc694 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Thu, 1 Aug 2019 11:50:11 +0800 Subject: [PATCH 3/3] fix ci --- planner/core/logical_plan_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index f26d1a6722dd7..5b2ef7760323a 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -2413,11 +2413,11 @@ func (s *testPlanSuite) TestWindowFunction(c *C) { result: "[planner:1235]This version of TiDB doesn't yet support '(DISTINCT ..)'", }, { - sql: "SELECT NTH_VALUE(a, 1) FROM LAST over (partition by b order by b), a FROM t1;", + sql: "SELECT NTH_VALUE(a, 1) FROM LAST over (partition by b order by b), a FROM t", result: "[planner:1235]This version of TiDB doesn't yet support 'FROM LAST'", }, { - sql: "SELECT NTH_VALUE(a, 1) FROM LAST IGNORE NULLS over (partition by b order by b), a FROM t1", + sql: "SELECT NTH_VALUE(a, 1) FROM LAST IGNORE NULLS over (partition by b order by b), a FROM t", result: "[planner:1235]This version of TiDB doesn't yet support 'IGNORE NULLS'", }, }