Skip to content

Commit

Permalink
session_test, plan_test: move out some tests. (pingcap#5814)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfei1991 authored and coocood committed Feb 9, 2018
1 parent 45f00e8 commit 039ad96
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
5 changes: 1 addition & 4 deletions plan/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ func (er *expressionRewriter) Enter(inNode ast.Node) (ast.Node, bool) {
index, ok = er.aggrMap[v]
}
if !ok {
er.err = errors.New("Can't appear aggrFunctions")
if er.b.curClause == groupByClause {
er.err = ErrInvalidGroupFuncUse
}
er.err = ErrInvalidGroupFuncUse
return inNode, true
}
er.ctxStack = append(er.ctxStack, er.schema.Columns[index])
Expand Down
20 changes: 20 additions & 0 deletions plan/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,26 @@ func (s *testPlanSuite) TestValidate(c *C) {
sql: "select * from t t1 use index(e)",
err: ErrKeyDoesNotExist,
},
{
sql: "select a from t having c2",
err: ErrUnknownColumn,
},
{
sql: "select a from t group by c2 + 1 having c2",
err: ErrUnknownColumn,
},
{
sql: "select a as b, b from t having b",
err: ErrAmbiguous,
},
{
sql: "select a + 1 from t having a",
err: ErrUnknownColumn,
},
{
sql: "select a from t having sum(avg(a))",
err: ErrInvalidGroupFuncUse,
},
}
for _, tt := range tests {
sql := tt.sql
Expand Down
14 changes: 7 additions & 7 deletions plan/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ func existsCartesianProduct(p LogicalPlan) bool {

// Optimizer error codes.
const (
CodeOperandColumns terror.ErrCode = 1
CodeInvalidWildCard = 3
CodeUnsupported = 4
CodeInvalidGroupFuncUse = 5
CodeStmtNotFound = 7
CodeWrongParamCount = 8
CodeSchemaChanged = 9
CodeOperandColumns terror.ErrCode = 1
CodeInvalidWildCard = 3
CodeUnsupported = 4
CodeStmtNotFound = 7
CodeWrongParamCount = 8
CodeSchemaChanged = 9

// MySQL error code.
CodeInvalidGroupFuncUse = mysql.ErrInvalidGroupFuncUse
CodeIllegalReference = mysql.ErrIllegalReference
CodeNoDB = mysql.ErrNoDB
CodeUnknownExplainFormat = mysql.ErrUnknownExplainFormat
Expand Down
21 changes: 0 additions & 21 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,6 @@ func (s *testSessionSuite) TestSchemaCheckerSimple(c *C) {
c.Assert(result, Equals, domain.ResultUnknown)
}

func (s *testSessionSuite) TestHaving(c *C) {
defer testleak.AfterTest(c)()
dbName := "test_having"
dropDBSQL := fmt.Sprintf("drop database %s;", dbName)
se := newSession(c, s.store, dbName)
mustExecFailed(c, se, "select c1 from t having c2")
mustExecFailed(c, se, "select c1 from t having c2 + 1")
mustExecFailed(c, se, "select c1 from t group by c2 + 1 having c2")
mustExecFailed(c, se, "select c1 from t group by c2 + 1 having c2 + 1")
mustExecFailed(c, se, "select c1 as c2, c2 from t having c2")
mustExecFailed(c, se, "select c1 as c2, c2 from t having c2 + 1")
mustExecFailed(c, se, "select c1 as a, c2 as a from t having a")
mustExecFailed(c, se, "select c1 as a, c2 as a from t having a + 1")
mustExecFailed(c, se, "select c1 + 1 from t having c1")
mustExecFailed(c, se, "select c1 + 1 from t having c1 + 1")
mustExecFailed(c, se, "select a.c1 as c, b.c1 as d from t as a, t as b having c1")
mustExecFailed(c, se, "select 1 from t having sum(avg(c1))")

mustExecSQL(c, se, dropDBSQL)
}

func (s *testSessionSuite) TestSetGlobalTZ(c *C) {
defer testleak.AfterTest(c)()
dbName := "testTZ"
Expand Down

0 comments on commit 039ad96

Please sign in to comment.