Skip to content

AlterTableChangeColumnDeltaCommand

AlterTableChangeColumnDeltaCommand is an AlterDeltaTableCommand to change (alter) the name, the comment, the nullability, the position and the data type of a column (of a DeltaTableV2).

AlterTableChangeColumnDeltaCommand is used when DeltaCatalog.alterTable is requested to execute ColumnChanges (Spark SQL).

ColumnChange SQL
RenameColumn (Spark SQL) ALTER TABLE RENAME COLUMN (Spark SQL)
UpdateColumnComment ALTER TABLE CHANGE COLUMN COMMENT
UpdateColumnNullability ALTER TABLE CHANGE COLUMN (SET | DROP) NOT NULL
UpdateColumnPosition ALTER TABLE CHANGE COLUMN (FIRST | AFTER)
UpdateColumnType ALTER TABLE CHANGE COLUMN TYPE

Creating Instance

AlterTableChangeColumnDeltaCommand takes the following to be created:

  • DeltaTableV2
  • Column Path
  • Column Name
  • New Column (as StructField)
  • ColumnPosition (optional)
  • (unused) syncIdentity flag

AlterTableChangeColumnDeltaCommand is created when:

Executing Command

run(
  sparkSession: SparkSession): Seq[Row]

run starts a transaction.

run asserts that the column is available (in the schema of the metadata of the transaction).

run transforms the current (old) schema to a new one based on the column changes (given by newColumn). As part of the changes, for every column, run checks whether column mapping is used to determine the column name.

run...FIXME

run updates the metadata (for the active transaction).

run commits the transaction with the following operation (and no actions):

  1. RENAME COLUMN when the name of the given newColumn is different from the given columnName
  2. CHANGE COLUMN, otherwise

In the end, run returns an empty collection.

Updating Metadata

In the end, run requests the OptimisticTransaction to update the Metadata (with the new newMetadata) and commit (with no Actions and ChangeColumn operation).


run is part of the RunnableCommand (Spark SQL) abstraction.

LeafRunnableCommand

AlterTableChangeColumnDeltaCommand is a LeafRunnableCommand (Spark SQL).

IgnoreCachedData

AlterTableChangeColumnDeltaCommand is a IgnoreCachedData (Spark SQL).