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:
- ResolveSessionCatalog logical resolution rule is executed (and resolves AddColumns logical operator)
Executing Command¶
RunnableCommand
run is part of the RunnableCommand abstraction.
run verifyAlterTableAddColumn (with the SessionCatalog).
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:
- The table is not a view
- 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:
CSVFileFormatorCSVDataSourceV2JsonFileFormatorJsonDataSourceV2- ParquetFileFormat or
ParquetDataSourceV2 OrcFileFormatorOrcDataSourceV2
Otherwise, verifyAlterTableAddColumn throws an AnalysisException: