github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/batch.go (about) 1 // Copyright 2023 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package tree 12 13 // Batch represents a BATCH clause. 14 type Batch struct { 15 Params []BatchParam 16 } 17 18 var _ NodeFormatter = &Batch{} 19 20 type BatchParam interface { 21 NodeFormatter 22 } 23 24 // SizeBatchParam represents a BATCH (SIZE size) parameter. 25 type SizeBatchParam struct { 26 // Size is the expression specified by SIZE <size>. 27 // It must be positive. 28 Size Expr 29 } 30 31 // BatchParam represents a BATCH (param) parameter. 32 var _ BatchParam = &SizeBatchParam{} 33 34 // Format implements NodeFormatter. 35 func (p *SizeBatchParam) Format(ctx *FmtCtx) { 36 ctx.WriteString("SIZE ") 37 p.Size.Format(ctx) 38 } 39 40 // Format implements the NodeFormatter interface. 41 func (b *Batch) Format(ctx *FmtCtx) { 42 if b == nil { 43 return 44 } 45 ctx.WriteString("BATCH ") 46 params := b.Params 47 if len(params) > 0 { 48 ctx.WriteString("(") 49 for i, param := range params { 50 if i > 0 { 51 ctx.WriteString(",") 52 } 53 param.Format(ctx) 54 } 55 ctx.WriteString(") ") 56 } 57 }