Class AlterTableAddColumns

java.lang.Object
com.datastax.astra.client.tables.commands.AlterTableAddColumns
All Implemented Interfaces:
AlterTableOperation

public final class AlterTableAddColumns extends Object implements AlterTableOperation
Represents an operation to add columns to an existing table in a database schema. This class implements the AlterTableOperation interface, providing functionality to define new columns and their types for the "alter table add" operation.

Example usage:

 
 AlterTableAddColumns operation = new AlterTableAddColumns()
     .ifNotExists()
     .addColumn("name", ColumnTypes.TEXT)
     .addColumnInt("age")
     .addColumnMap("attributes", ColumnTypes.TEXT, ColumnTypes.TEXT);
 
 

Key Features:

  • Supports adding columns with various data types, including primitive, list, set, and map types.
  • Chainable methods for building operations fluently.
  • Ability to specify the "IF NOT EXISTS" clause to avoid errors if the column already exists.
  • Constructor Details

    • AlterTableAddColumns

      public AlterTableAddColumns()
      Constructs a new AlterTableAddColumns instance.
  • Method Details

    • getOperationName

      public String getOperationName()
      Returns the name of this operation. Always returns "add" for this operation type.
      Specified by:
      getOperationName in interface AlterTableOperation
      Returns:
      the operation name.
    • addColumn

      public AlterTableAddColumns addColumn(String name, ColumnTypes type)
      Adds a column with the specified name and type to the table.
      Parameters:
      name - the name of the column.
      type - the type of the column.
      Returns:
      the current instance for chaining.
    • addColumnVector

      public AlterTableAddColumns addColumnVector(String name, ColumnDefinitionVector cdv)
      Adds a column defined by a ColumnDefinitionVector.
      Parameters:
      name - the name of the column.
      cdv - the column definition vector.
      Returns:
      the current instance for chaining.
    • addColumnText

      public AlterTableAddColumns addColumnText(String name)
      Adds a column with the TEXT type.
      Parameters:
      name - the name of the column.
      Returns:
      the current instance for chaining.
    • addColumnInt

      public AlterTableAddColumns addColumnInt(String name)
      Adds a column with the INT type.
      Parameters:
      name - the name of the column.
      Returns:
      the current instance for chaining.
    • addColumnBoolean

      public AlterTableAddColumns addColumnBoolean(String name)
      Adds a column with the BOOLEAN type.
      Parameters:
      name - the name of the column.
      Returns:
      the current instance for chaining.
    • addColumnList

      public AlterTableAddColumns addColumnList(String name, ColumnTypes valueType)
      Adds a column with the LIST type, where the list items are of the specified value type.
      Parameters:
      name - the name of the column.
      valueType - the type of the values in the list.
      Returns:
      the current instance for chaining.
    • addColumnSet

      public AlterTableAddColumns addColumnSet(String name, ColumnTypes valueType)
      Adds a column with the SET type, where the set items are of the specified value type.
      Parameters:
      name - the name of the column.
      valueType - the type of the values in the set.
      Returns:
      the current instance for chaining.
    • addColumnMap

      public AlterTableAddColumns addColumnMap(String name, ColumnTypes keyType, ColumnTypes valueType)
      Adds a column with the MAP type, where the keys and values are of the specified types.
      Parameters:
      name - the name of the column.
      keyType - the type of the keys in the map.
      valueType - the type of the values in the map.
      Returns:
      the current instance for chaining.