Skip to content

Commit

Permalink
build proj
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewDi committed Dec 20, 2018
1 parent 996dbb7 commit 5a5a47c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3448,6 +3448,6 @@ func (s *testSuite) TestSelectView(c *C) {
tk.MustQuery("select * from view1;").Check(testkit.Rows("1 2"))
tk.MustQuery("select * from view2;").Check(testkit.Rows("1 2"))
tk.MustQuery("select * from view3;").Check(testkit.Rows("1 2"))
defer tk.MustExec("drop table view_t;")
defer tk.MustExec("drop view view1,view2,view3;")
tk.MustExec("drop table view_t;")
tk.MustExec("drop view view1,view2,view3;")
}
22 changes: 14 additions & 8 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2009,19 +2009,25 @@ func (b *PlanBuilder) buildDataSourceFromView(dbName model.CIStr, tableInfo *mod
if err != nil {
return nil, err
}
var viewCols []*expression.Column
var projExprs []*expression.Column
for i := range tableInfo.View.Cols {
col := selectLogicalPlan.Schema().FindColumnByName(tableInfo.View.Cols[i].L)
if col == nil {
return nil, ErrViewInvalid.GenWithStackByArgs(dbName.L, tableInfo.Name.L)
}
col.ColName = tableInfo.Cols()[i].Name
col.OrigColName = tableInfo.View.Cols[i]
viewCols = append(viewCols, col)
return nil, ErrViewInvalid.GenWithStackByArgs(dbName.O, tableInfo.Name.O)
}
projExprs = append(projExprs, &expression.Column{
UniqueID: b.ctx.GetSessionVars().AllocPlanColumnID(),
TblName: col.TblName,
OrigTblName: col.OrigTblName,
ColName: tableInfo.Cols()[i].Name,
OrigColName: tableInfo.View.Cols[i],
DBName: dbName,
RetType: col.GetType(),
})
}
projUponView := LogicalProjection{Exprs: expression.Column2Exprs(viewCols)}.Init(b.ctx)
projUponView := LogicalProjection{Exprs: expression.Column2Exprs(projExprs)}.Init(b.ctx)
projUponView.SetChildren(selectLogicalPlan.(LogicalPlan))
projUponView.SetSchema(expression.NewSchema(viewCols...))
projUponView.SetSchema(expression.NewSchema(projExprs...))
return projUponView, nil
}

Expand Down

0 comments on commit 5a5a47c

Please sign in to comment.