github.com/matrixorigin/matrixone@v0.7.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  // the REPLACE statement.
    18  type Replace struct {
    19  	statementImpl
    20  	Table          TableExpr
    21  	PartitionNames IdentifierList
    22  	Columns        IdentifierList
    23  	Rows           *Select
    24  }
    25  
    26  func (node *Replace) Format(ctx *FmtCtx) {
    27  	ctx.WriteString("replace into ")
    28  	node.Table.Format(ctx)
    29  
    30  	if node.PartitionNames != nil {
    31  		ctx.WriteString(" partition(")
    32  		node.PartitionNames.Format(ctx)
    33  		ctx.WriteByte(')')
    34  	}
    35  
    36  	if node.Columns != nil {
    37  		ctx.WriteString(" (")
    38  		node.Columns.Format(ctx)
    39  		ctx.WriteByte(')')
    40  	}
    41  	if node.Rows != nil {
    42  		ctx.WriteByte(' ')
    43  		node.Rows.Format(ctx)
    44  	}
    45  }
    46  
    47  func (node *Replace) GetStatementType() string { return "Replace" }
    48  func (node *Replace) GetQueryType() string     { return QueryTypeDML }
    49  
    50  func NewReplace(t TableExpr, c IdentifierList, r *Select, p IdentifierList) *Replace {
    51  	return &Replace{
    52  		Table:          t,
    53  		Columns:        c,
    54  		Rows:           r,
    55  		PartitionNames: p,
    56  	}
    57  }