github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/view.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tree 16 17 import "github.com/matrixorigin/matrixone/pkg/common/reuse" 18 19 func init() { 20 reuse.CreatePool[CreateView]( 21 func() *CreateView { return &CreateView{} }, 22 func(c *CreateView) { c.reset() }, 23 reuse.DefaultOptions[CreateView](), //. 24 ) //WithEnableChecker() 25 } 26 27 type CreateView struct { 28 statementImpl 29 Replace bool 30 Name *TableName 31 ColNames IdentifierList 32 AsSource *Select 33 IfNotExists bool 34 } 35 36 func NewCreateView(replace bool, name *TableName, colNames IdentifierList, asSource *Select, ifNotExists bool) *CreateView { 37 c := reuse.Alloc[CreateView](nil) 38 c.Replace = replace 39 c.Name = name 40 c.ColNames = colNames 41 c.AsSource = asSource 42 c.IfNotExists = ifNotExists 43 return c 44 } 45 46 func (node *CreateView) Free() { 47 reuse.Free[CreateView](node, nil) 48 } 49 50 func (node *CreateView) Format(ctx *FmtCtx) { 51 ctx.WriteString("create ") 52 53 if node.Replace { 54 ctx.WriteString("or replace ") 55 } 56 57 ctx.WriteString("view ") 58 59 if node.IfNotExists { 60 ctx.WriteString("if not exists ") 61 } 62 63 node.Name.Format(ctx) 64 if len(node.ColNames) > 0 { 65 ctx.WriteString(" (") 66 node.ColNames.Format(ctx) 67 ctx.WriteByte(')') 68 } 69 ctx.WriteString(" as ") 70 node.AsSource.Format(ctx) 71 } 72 73 func (node *CreateView) reset() { 74 // if node.Name != nil { 75 // node.Name.Free() 76 // } 77 // if node.AsSource != nil { 78 // node.AsSource.Free() 79 // } 80 *node = CreateView{} 81 } 82 83 func (node CreateView) TypeName() string { return "tree.CreateView" } 84 85 func (node *CreateView) GetStatementType() string { return "Create View" } 86 func (node *CreateView) GetQueryType() string { return QueryTypeDDL }