Skip to content

Commit cd68330

Browse files
author
James Cor
committed
have create views implement target schema
1 parent 9ee86c8 commit cd68330

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

sql/information_schema/columns_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func getRowsFromViews(ctx *sql.Context, catalog sql.Catalog, db DbWithNames, pri
384384
}
385385
privSetTbl := privSetDb.Table(view.Name)
386386
curPrivSetMap := getCurrentPrivSetMapForColumn(privSetDb.ToSlice(), privSetMap)
387-
for i, col := range createViewNode.Definition.Schema() {
387+
for i, col := range createViewNode.TargetSchema() {
388388
r := getRowFromColumn(ctx, i, col, db.CatalogName, db.SchemaName, view.Name, "", privSetTbl, curPrivSetMap)
389389
if r != nil {
390390
rows = append(rows, r)

sql/plan/create_view.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
type CreateView struct {
3030
UnaryNode
3131
database sql.Database
32+
targetSchema sql.Schema
3233
Name string
3334
IsReplace bool
3435
Definition *SubqueryAlias
@@ -41,6 +42,7 @@ type CreateView struct {
4142

4243
var _ sql.Node = (*CreateView)(nil)
4344
var _ sql.CollationCoercible = (*CreateView)(nil)
45+
var _ sql.SchemaTarget = (*CreateView)(nil)
4446

4547
// NewCreateView creates a CreateView node with the specified parameters,
4648
// setting its catalog to nil.
@@ -135,6 +137,18 @@ func (cv *CreateView) WithDatabase(database sql.Database) (sql.Node, error) {
135137
return &newCreate, nil
136138
}
137139

140+
// WithTargetSchema implements the SchemaTarget interface.
141+
func (cv *CreateView) WithTargetSchema(sch sql.Schema) (sql.Node, error) {
142+
ncv := *cv
143+
ncv.targetSchema = sch
144+
return &ncv, nil
145+
}
146+
147+
// TargetSchema implements the SchemaTarget interface.
148+
func (cv *CreateView) TargetSchema() sql.Schema {
149+
return cv.targetSchema
150+
}
151+
138152
// GetIsUpdatableFromCreateView returns whether the view is updatable or not.
139153
// https://dev.mysql.com/doc/refman/8.0/en/view-updatability.html
140154
func GetIsUpdatableFromCreateView(cv *CreateView) bool {

sql/planbuilder/create_ddl.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ func (b *Builder) buildCreateView(inScope *scope, subQuery string, fullQuery str
472472
dbName = b.ctx.GetCurrentDatabase()
473473
}
474474
db := b.resolveDb(dbName)
475-
outScope.node = plan.NewCreateView(db, c.ViewSpec.ViewName.Name.String(), queryAlias, c.OrReplace, subQuery, c.ViewSpec.Algorithm, definer, c.ViewSpec.Security)
475+
createView := plan.NewCreateView(db, c.ViewSpec.ViewName.Name.String(), queryAlias, c.OrReplace, subQuery, c.ViewSpec.Algorithm, definer, c.ViewSpec.Security)
476+
outScope.node = b.modifySchemaTarget(queryScope, createView, createView.Definition.Schema())
477+
476478
return outScope
477479
}

0 commit comments

Comments
 (0)