Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add AlterTableReplaceColumnsCommand class
  • Loading branch information
manu-olx committed Jun 4, 2019
commit 59332d00b386297a945942d667f69786a7a37461
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,38 @@ case class AlterTableAddColumnsCommand(
}
}

/**
* A command that replace columns in a table
* The syntax of using this command in SQL is:
* {{{
* ALTER TABLE table_identifier
* REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...);
* }}}
*/
case class AlterTableReplaceColumnsCommand(
table: TableIdentifier,
colsToReplace: Seq[StructField]) extends AlterTableAddReplaceColumnsCommandsBase {
override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val catalogTable = verifyAlterTableAddReplaceColumn(
sparkSession.sessionState.conf, catalog, table)

try {
sparkSession.catalog.uncacheTable(table.quotedString)
} catch {
case NonFatal(e) =>
log.warn(s"Exception when attempting to uncache table ${table.quotedString}", e)
}
catalog.refreshTable(table)

verifyColumnsToAddReplace(table, catalogTable, colsToReplace)

catalog.alterTableDataSchema(table, StructType(colsToReplace))
Seq.empty[Row]
}
}


/**
* A command that loads data into a Hive table.
*
Expand Down