github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/alter_changefeed.go (about)

     1  // Copyright 2022 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  // AlterChangefeed represents an ALTER CHANGEFEED statement.
    14  type AlterChangefeed struct {
    15  	Jobs Expr
    16  	Cmds AlterChangefeedCmds
    17  }
    18  
    19  var _ Statement = &AlterChangefeed{}
    20  
    21  // Format implements the NodeFormatter interface.
    22  func (node *AlterChangefeed) Format(ctx *FmtCtx) {
    23  	ctx.WriteString(`ALTER CHANGEFEED `)
    24  	ctx.FormatNode(node.Jobs)
    25  	ctx.FormatNode(&node.Cmds)
    26  }
    27  
    28  // AlterChangefeedCmds represents a list of changefeed alterations
    29  type AlterChangefeedCmds []AlterChangefeedCmd
    30  
    31  // Format implements the NodeFormatter interface.
    32  func (node *AlterChangefeedCmds) Format(ctx *FmtCtx) {
    33  	for i, n := range *node {
    34  		if i > 0 {
    35  			ctx.WriteString(" ")
    36  		}
    37  		ctx.FormatNode(n)
    38  	}
    39  }
    40  
    41  // AlterChangefeedCmd represents a changefeed modification operation.
    42  type AlterChangefeedCmd interface {
    43  	NodeFormatter
    44  	// Placeholder function to ensure that only desired types
    45  	// (AlterChangefeed*) conform to the AlterChangefeedCmd interface.
    46  	alterChangefeedCmd()
    47  }
    48  
    49  func (*AlterChangefeedAddTarget) alterChangefeedCmd()    {}
    50  func (*AlterChangefeedDropTarget) alterChangefeedCmd()   {}
    51  func (*AlterChangefeedSetOptions) alterChangefeedCmd()   {}
    52  func (*AlterChangefeedUnsetOptions) alterChangefeedCmd() {}
    53  
    54  var _ AlterChangefeedCmd = &AlterChangefeedAddTarget{}
    55  var _ AlterChangefeedCmd = &AlterChangefeedDropTarget{}
    56  var _ AlterChangefeedCmd = &AlterChangefeedSetOptions{}
    57  var _ AlterChangefeedCmd = &AlterChangefeedUnsetOptions{}
    58  
    59  // AlterChangefeedAddTarget represents an ADD <targets> command
    60  type AlterChangefeedAddTarget struct {
    61  	Targets ChangefeedTargets
    62  	Options KVOptions
    63  }
    64  
    65  // Format implements the NodeFormatter interface.
    66  func (node *AlterChangefeedAddTarget) Format(ctx *FmtCtx) {
    67  	ctx.WriteString(" ADD ")
    68  	ctx.FormatNode(&node.Targets)
    69  	if node.Options != nil {
    70  		ctx.WriteString(" WITH ")
    71  		ctx.FormatNode(&node.Options)
    72  	}
    73  }
    74  
    75  // AlterChangefeedDropTarget represents an DROP <targets> command
    76  type AlterChangefeedDropTarget struct {
    77  	Targets ChangefeedTargets
    78  }
    79  
    80  // Format implements the NodeFormatter interface.
    81  func (node *AlterChangefeedDropTarget) Format(ctx *FmtCtx) {
    82  	ctx.WriteString(" DROP ")
    83  	ctx.FormatNode(&node.Targets)
    84  }
    85  
    86  // AlterChangefeedSetOptions represents an SET <options> command
    87  type AlterChangefeedSetOptions struct {
    88  	Options KVOptions
    89  }
    90  
    91  // Format implements the NodeFormatter interface.
    92  func (node *AlterChangefeedSetOptions) Format(ctx *FmtCtx) {
    93  	ctx.WriteString(" SET ")
    94  	ctx.FormatNode(&node.Options)
    95  }
    96  
    97  // AlterChangefeedUnsetOptions represents an UNSET <options> command
    98  type AlterChangefeedUnsetOptions struct {
    99  	Options NameList
   100  }
   101  
   102  // Format implements the NodeFormatter interface.
   103  func (node *AlterChangefeedUnsetOptions) Format(ctx *FmtCtx) {
   104  	ctx.WriteString(" UNSET ")
   105  	ctx.FormatNode(&node.Options)
   106  }