From 1665ff9f4e6e21b6102c117d556d1abdee5b12c8 Mon Sep 17 00:00:00 2001 From: HuaiyuXu <391585975@qq.com> Date: Thu, 22 Nov 2018 18:12:55 +0800 Subject: [PATCH] ast, plan: return error when the arg of VALUES() function is not a column (#7817) (#8404) --- ast/expressions.go | 4 +++- plan/logical_plan_builder.go | 4 ++++ plan/logical_plan_test.go | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ast/expressions.go b/ast/expressions.go index 2b1d696611be4..62b0b833bc2e1 100644 --- a/ast/expressions.go +++ b/ast/expressions.go @@ -931,7 +931,9 @@ func (n *ValuesExpr) Accept(v Visitor) (Node, bool) { if !ok { return n, false } - n.Column = node.(*ColumnNameExpr) + // `node` may be *ast.ValueExpr, to avoid panic, we write `ok` but do not use + // it. + n.Column, ok = node.(*ColumnNameExpr) return v.Leave(n) } diff --git a/plan/logical_plan_builder.go b/plan/logical_plan_builder.go index 4fd2f4acd5f6c..735103720677c 100644 --- a/plan/logical_plan_builder.go +++ b/plan/logical_plan_builder.go @@ -1179,6 +1179,10 @@ func (g *gbyResolver) Leave(inNode ast.Node) (ast.Node, bool) { return inNode, false } return ret, true + case *ast.ValuesExpr: + if v.Column == nil { + g.err = ErrUnknownColumn.GenByArgs("", "VALUES() function") + } } return inNode, true } diff --git a/plan/logical_plan_test.go b/plan/logical_plan_test.go index fea84c92a37af..17eb4645cf348 100644 --- a/plan/logical_plan_test.go +++ b/plan/logical_plan_test.go @@ -1644,6 +1644,7 @@ func (s *testPlanSuite) TestNameResolver(c *C) { {"select a from t group by t11.c1", "[planner:1054]Unknown column 't11.c1' in 'group statement'"}, {"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'"}, } for _, t := range tests {