Skip to content

AlterTableAddColumnsCommand Logical Runnable Command

AlterTableAddColumnsCommand is a LeafRunnableCommand that represents AddColumns logical operator.

Creating Instance

AlterTableAddColumnsCommand takes the following to be created:

  • Table (TableIdentifier)
  • Columns to Add (StructFields)

AlterTableAddColumnsCommand is created when:

Executing Command

RunnableCommand
run(
  sparkSession: SparkSession): Seq[Row]

run is part of the RunnableCommand abstraction.

run verifyAlterTableAddColumn (with the SessionCatalog).

run uncaches the table.

run requests the SessionCatalog to refreshTable.

run checks the column names (against any duplications) and types, and re-constructs the original schema of columns from their column metadata (if there is any).

run requests the SessionCatalog to alterTableDataSchema.

verifyAlterTableAddColumn

verifyAlterTableAddColumn(
  conf: SQLConf,
  catalog: SessionCatalog,
  table: TableIdentifier): CatalogTable

verifyAlterTableAddColumn asserts that the table is as follows:

  1. The table is not a view
  2. The table is a Hive table or one of the supported FileFormats

verifyAlterTableAddColumn requests the given SessionCatalog for the getTempViewOrPermanentTableMetadata.

verifyAlterTableAddColumn throws an AnalysisException if the table is a VIEW:

ALTER ADD COLUMNS does not support views.
You must drop and re-create the views for adding the new columns. Views: [table]

For a Spark table (that is non-Hive), verifyAlterTableAddColumn finds the implementation of the table provider and makes sure that the table provider is one of the following supported file formats:

  • CSVFileFormat or CSVDataSourceV2
  • JsonFileFormat or JsonDataSourceV2
  • ParquetFileFormat or ParquetDataSourceV2
  • OrcFileFormat or OrcDataSourceV2

Otherwise, verifyAlterTableAddColumn throws an AnalysisException:

ALTER ADD COLUMNS does not support datasource table with type [tableType].
You must drop and re-create the table for adding the new columns. Tables: [table]