Skip to content

Commit

Permalink
ast, plan: return error when the arg of VALUES() function is not a co…
Browse files Browse the repository at this point in the history
…lumn (#7817) (#8404)
  • Loading branch information
XuHuaiyu authored and zz-jason committed Nov 22, 2018
1 parent 4dd328b commit 1665ff9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ast/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions plan/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions plan/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1665ff9

Please sign in to comment.