github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/replace.go (about) 1 // Copyright 2021 - 2022 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[Replace]( 21 func() *Replace { return &Replace{} }, 22 func(r *Replace) { r.reset() }, 23 reuse.DefaultOptions[Replace](), //. 24 ) //WithEnableChecker() 25 } 26 27 // the REPLACE statement. 28 type Replace struct { 29 statementImpl 30 Table TableExpr 31 PartitionNames IdentifierList 32 Columns IdentifierList 33 Rows *Select 34 } 35 36 func (node *Replace) Format(ctx *FmtCtx) { 37 ctx.WriteString("replace into ") 38 node.Table.Format(ctx) 39 40 if node.PartitionNames != nil { 41 ctx.WriteString(" partition(") 42 node.PartitionNames.Format(ctx) 43 ctx.WriteByte(')') 44 } 45 46 if node.Columns != nil { 47 ctx.WriteString(" (") 48 node.Columns.Format(ctx) 49 ctx.WriteByte(')') 50 } 51 if node.Rows != nil { 52 ctx.WriteByte(' ') 53 node.Rows.Format(ctx) 54 } 55 } 56 57 func (node *Replace) GetStatementType() string { return "Replace" } 58 func (node *Replace) GetQueryType() string { return QueryTypeDML } 59 60 func NewReplace(t TableExpr, c IdentifierList, r *Select, p IdentifierList) *Replace { 61 replace := reuse.Alloc[Replace](nil) 62 replace.Table = t 63 replace.Columns = c 64 replace.Rows = r 65 replace.PartitionNames = p 66 return replace 67 } 68 69 func (node *Replace) Free() { 70 reuse.Free[Replace](node, nil) 71 } 72 73 func (node *Replace) reset() { 74 // if node.Rows != nil { 75 // node.Rows.Free() 76 // } 77 *node = Replace{} 78 } 79 80 func (node Replace) TypeName() string { return "tree.Replace" }