github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/alter_index.go (about)

     1  // Copyright 2017 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  // AlterIndex represents an ALTER INDEX statement.
    14  type AlterIndex struct {
    15  	IfExists bool
    16  	Index    TableIndexName
    17  	Cmds     AlterIndexCmds
    18  }
    19  
    20  var _ Statement = &AlterIndex{}
    21  
    22  // Format implements the NodeFormatter interface.
    23  func (node *AlterIndex) Format(ctx *FmtCtx) {
    24  	ctx.WriteString("ALTER INDEX ")
    25  	if node.IfExists {
    26  		ctx.WriteString("IF EXISTS ")
    27  	}
    28  	ctx.FormatNode(&node.Index)
    29  	ctx.FormatNode(&node.Cmds)
    30  }
    31  
    32  // AlterIndexCmds represents a list of index alterations.
    33  type AlterIndexCmds []AlterIndexCmd
    34  
    35  // Format implements the NodeFormatter interface.
    36  func (node *AlterIndexCmds) Format(ctx *FmtCtx) {
    37  	for i, n := range *node {
    38  		if i > 0 {
    39  			ctx.WriteString(",")
    40  		}
    41  		ctx.FormatNode(n)
    42  	}
    43  }
    44  
    45  // AlterIndexCmd represents an index modification operation.
    46  type AlterIndexCmd interface {
    47  	NodeFormatter
    48  	// Placeholder function to ensure that only desired types
    49  	// (AlterIndex*) conform to the AlterIndexCmd interface.
    50  	alterIndexCmd()
    51  }
    52  
    53  func (*AlterIndexPartitionBy) alterIndexCmd() {}
    54  
    55  var _ AlterIndexCmd = &AlterIndexPartitionBy{}
    56  
    57  // AlterIndexPartitionBy represents an ALTER INDEX PARTITION BY
    58  // command.
    59  type AlterIndexPartitionBy struct {
    60  	*PartitionBy
    61  }
    62  
    63  // Format implements the NodeFormatter interface.
    64  func (node *AlterIndexPartitionBy) Format(ctx *FmtCtx) {
    65  	ctx.FormatNode(node.PartitionBy)
    66  }