Skip to content

Commit

Permalink
planner: fix wrong message when group by a window or agg func with …
Browse files Browse the repository at this point in the history
…an `as` (#17572) (#20249)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Oct 3, 2020
1 parent 9518e90 commit 74fac60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1823,12 +1823,12 @@ func (g *gbyResolver) Leave(inNode ast.Node) (ast.Node, bool) {
}
ret := g.fields[pos-1].Expr
ret.Accept(extractor)
if len(extractor.AggFuncs) != 0 {
g.err = ErrWrongGroupField.GenWithStackByArgs(g.fields[pos-1].Text())
return inNode, false
}
if _, ok := ret.(*ast.WindowFuncExpr); ok {
g.err = ErrWrongGroupField.GenWithStackByArgs(g.fields[pos-1].Text())
if len(extractor.AggFuncs) != 0 || ast.HasWindowFlag(ret) {
fieldName := g.fields[pos-1].AsName.String()
if fieldName == "" {
fieldName = g.fields[pos-1].Text()
}
g.err = ErrWrongGroupField.GenWithStackByArgs(fieldName)
return inNode, false
}
return ret, true
Expand Down
4 changes: 3 additions & 1 deletion planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,10 @@ func (s *testPlanSuite) TestNameResolver(c *C) {
{"delete a from (select * from t ) as a, t", "[planner:1288]The target table a of the DELETE is not updatable"},
{"delete b from (select * from t ) as a, t", "[planner:1109]Unknown table 'b' in MULTI DELETE"},
{"select '' as fakeCol from t group by values(fakeCol)", "[planner:1054]Unknown column '' in 'VALUES() function'"},
{"update t, (select * from ht) as b set b.a = t.a", "[planner:1288]The target table b of the UPDATE is not updatable"},
{"update t, (select * from t) as b set b.a = t.a", "[planner:1288]The target table b of the UPDATE is not updatable"},
{"select row_number() over () from t group by 1", "[planner:1056]Can't group on 'row_number() over ()'"},
{"select row_number() over () as x from t group by 1", "[planner:1056]Can't group on 'x'"},
{"select sum(a) as x from t group by 1", "[planner:1056]Can't group on 'x'"},
}

ctx := context.Background()
Expand Down

0 comments on commit 74fac60

Please sign in to comment.