*: address comments

This commit is contained in:
xia
2016-01-06 12:40:10 +08:00
parent e0f944c260
commit 896ee778a2
4 changed files with 23 additions and 35 deletions

View File

@ -91,7 +91,7 @@ type Executor interface {
type ShowDDL struct {
fields []*ast.ResultField
ctx context.Context
cnt int
done bool
}
// Fields implements Executor Fields interface.
@ -101,7 +101,7 @@ func (e *ShowDDL) Fields() []*ast.ResultField {
// Next implements Execution Next interface.
func (e *ShowDDL) Next() (*Row, error) {
if e.cnt != 0 {
if e.done {
return nil, nil
}
@ -115,23 +115,23 @@ func (e *ShowDDL) Next() (*Row, error) {
return nil, errors.Trace(err)
}
records := []interface{}{
rowData := []interface{}{
info.SchemaVer,
nil,
nil,
}
if info.Owner != nil {
records[1] = info.Owner.String()
rowData[1] = info.Owner.String()
}
if info.Job != nil {
records[2] = info.Job.String()
rowData[2] = info.Job.String()
}
row := &Row{}
row.Data = append(row.Data, records...)
row.Data = rowData
for i, f := range e.fields {
f.Expr.SetValue(records[i])
f.Expr.SetValue(rowData[i])
}
e.cnt++
e.done = true
return row, nil
}
@ -145,6 +145,7 @@ func (e *ShowDDL) Close() error {
type CheckTable struct {
tables []*ast.TableName
ctx context.Context
done bool
}
// Fields implements Executor Fields interface.
@ -154,6 +155,10 @@ func (e *CheckTable) Fields() []*ast.ResultField {
// Next implements Execution Next interface.
func (e *CheckTable) Next() (*Row, error) {
if e.done {
return nil, nil
}
dbName := model.NewCIStr(db.GetCurrentSchema(e.ctx))
is := sessionctx.GetDomain(e.ctx).InfoSchema()
txn, err := e.ctx.GetTxn(false)
@ -173,6 +178,7 @@ func (e *CheckTable) Next() (*Row, error) {
}
}
}
e.done = true
return nil, nil
}

View File

@ -53,6 +53,7 @@ func (s *testSuite) TestAdmin(c *C) {
c.Assert(err, IsNil)
row, err := r.Next()
c.Assert(err, IsNil)
c.Logf("row:%v\n", row)
c.Assert(row, NotNil)
r, err = tk.Exec("admin check table admin_test")

View File

@ -23,16 +23,14 @@ func Alternatives(p Plan) ([]Plan, error) {
case nil:
case *TableScan:
plans = tableScanAlternatives(x)
case *ShowDDL:
plans = showDDLAlternatives(x)
case *CheckTable:
plans = checkTableAlternatives(x)
case WithSrcPlan:
var err error
plans, err = planWithSrcAlternatives(x)
if err != nil {
return nil, errors.Trace(err)
}
case *ShowDDL:
case *CheckTable:
case *Prepare:
case *Execute:
case *Deallocate:
@ -67,17 +65,6 @@ func tableScanAlternatives(p *TableScan) []Plan {
return alts
}
func showDDLAlternatives(p *ShowDDL) []Plan {
sp := &ShowDDL{}
sp.SetFields(p.fields)
return []Plan{sp}
}
func checkTableAlternatives(p *CheckTable) []Plan {
return []Plan{&CheckTable{}}
}
// planWithSrcAlternatives shallow copies the WithSrcPlan,
// and set its src to src alternatives.
func planWithSrcAlternatives(p WithSrcPlan) ([]Plan, error) {

View File

@ -34,9 +34,6 @@ const (
CodeUnsupportedType = iota + 1
)
// Table Name.
const tableShowDDL = "SHOW_DDL"
// BuildPlan builds a plan from a node.
// returns ErrUnsupportedType if ast.Node type is not supported yet.
func BuildPlan(node ast.Node) (Plan, error) {
@ -216,11 +213,7 @@ func (b *planBuilder) buildPrepare(x *ast.PrepareStmt) Plan {
func (b *planBuilder) buildAdmin(adm *ast.AdminStmt) Plan {
if adm.Tp == ast.AdminCheckTable {
if adm.Tables != nil {
return &CheckTable{Tables: adm.Tables}
}
return nil
return &CheckTable{Tables: adm.Tables}
}
if adm.Tp == ast.AdminShowDDL {
@ -230,15 +223,16 @@ func (b *planBuilder) buildAdmin(adm *ast.AdminStmt) Plan {
return p
}
b.err = ErrUnsupportedType.Gen("Unsupported type %T", adm)
return nil
}
func buildShowDDLFields() []*ast.ResultField {
tbName := tableShowDDL
rfs := make([]*ast.ResultField, 0, 3)
rfs = append(rfs, buildResultField(tbName, "SCHEMA_VER", mysql.TypeLonglong, 4))
rfs = append(rfs, buildResultField(tbName, "OWNER", mysql.TypeVarchar, 64))
rfs = append(rfs, buildResultField(tbName, "Job", mysql.TypeVarchar, 128))
rfs = append(rfs, buildResultField("", "SCHEMA_VER", mysql.TypeLonglong, 4))
rfs = append(rfs, buildResultField("", "OWNER", mysql.TypeVarchar, 64))
rfs = append(rfs, buildResultField("", "Job", mysql.TypeVarchar, 128))
return rfs
}