github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/parsers/tree/with.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  type With struct {
    18  	statementImpl
    19  	IsRecursive bool
    20  	CTEs        []*CTE
    21  }
    22  
    23  func (node *With) Format(ctx *FmtCtx) {
    24  	ctx.WriteString("with ")
    25  	if node.IsRecursive {
    26  		ctx.WriteString("recursive ")
    27  	}
    28  	prefix := ""
    29  	for _, cte := range node.CTEs {
    30  		ctx.WriteString(prefix)
    31  		cte.Format(ctx)
    32  		prefix = ", "
    33  	}
    34  }
    35  func (node *With) GetStatementType() string { return "With" }
    36  func (node *With) GetQueryType() string     { return QueryTypeDQL }
    37  
    38  type CTE struct {
    39  	Name *AliasClause
    40  	Stmt Statement
    41  }
    42  
    43  func (node *CTE) Format(ctx *FmtCtx) {
    44  	node.Name.Format(ctx)
    45  	ctx.WriteString(" as (")
    46  	node.Stmt.Format(ctx)
    47  	ctx.WriteString(")")
    48  }