Interface TableChange
- All Known Subinterfaces:
TableChange.ColumnChange
- All Known Implementing Classes:
TableChange.AddColumn
,TableChange.DeleteColumn
,TableChange.RemoveProperty
,TableChange.RenameColumn
,TableChange.SetProperty
,TableChange.UpdateColumnComment
,TableChange.UpdateColumnDefaultValue
,TableChange.UpdateColumnNullability
,TableChange.UpdateColumnPosition
,TableChange.UpdateColumnType
TableCatalog.alterTable(org.apache.spark.sql.connector.catalog.Identifier, org.apache.spark.sql.connector.catalog.TableChange...)
. For example,
import TableChange._ val catalog = Catalogs.load(name) catalog.asTableCatalog.alterTable(ident, addColumn("x", IntegerType), renameColumn("a", "b"), deleteColumn("c") )
- Since:
- 3.0.0
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final class
A TableChange to add a field.static final class
Column position AFTER means the specified column should be put after the given `column`.static interface
static interface
static final class
A TableChange to delete a field.static final class
Column position FIRST means the specified column should be the first column.static final class
A TableChange to remove a table property.static final class
A TableChange to rename a field.static final class
A TableChange to set a table property.static final class
A TableChange to update the comment of a field.static final class
A TableChange to update the default value of a field.static final class
A TableChange to update the nullability of a field.static final class
A TableChange to update the position of a field.static final class
A TableChange to update the type of a field. -
Method Summary
Modifier and TypeMethodDescriptionstatic TableChange
Create a TableChange for adding an optional column.static TableChange
Create a TableChange for adding a column.static TableChange
Create a TableChange for adding a column.static TableChange
addColumn
(String[] fieldNames, DataType dataType, boolean isNullable, String comment, TableChange.ColumnPosition position, ColumnDefaultValue defaultValue) Create a TableChange for adding a column.static TableChange
deleteColumn
(String[] fieldNames, Boolean ifExists) Create a TableChange for deleting a field.static TableChange
removeProperty
(String property) Create a TableChange for removing a table property.static TableChange
renameColumn
(String[] fieldNames, String newName) Create a TableChange for renaming a field.static TableChange
setProperty
(String property, String value) Create a TableChange for setting a table property.static TableChange
updateColumnComment
(String[] fieldNames, String newComment) Create a TableChange for updating the comment of a field.static TableChange
updateColumnDefaultValue
(String[] fieldNames, String newDefaultValue) Create a TableChange for updating the default value of a field.static TableChange
updateColumnNullability
(String[] fieldNames, boolean nullable) Create a TableChange for updating the nullability of a field.static TableChange
updateColumnPosition
(String[] fieldNames, TableChange.ColumnPosition newPosition) Create a TableChange for updating the position of a field.static TableChange
updateColumnType
(String[] fieldNames, DataType newDataType) Create a TableChange for updating the type of a field that is nullable.
-
Method Details
-
setProperty
Create a TableChange for setting a table property.If the property already exists, it will be replaced with the new value.
- Parameters:
property
- the property namevalue
- the new property value- Returns:
- a TableChange for the addition
-
removeProperty
Create a TableChange for removing a table property.If the property does not exist, the change will succeed.
- Parameters:
property
- the property name- Returns:
- a TableChange for the addition
-
addColumn
Create a TableChange for adding an optional column.If the field already exists, the change will result in an
IllegalArgumentException
. If the new field is nested and its parent does not exist or is not a struct, the change will result in anIllegalArgumentException
.- Parameters:
fieldNames
- field names of the new columndataType
- the new column's data type- Returns:
- a TableChange for the addition
-
addColumn
Create a TableChange for adding a column.If the field already exists, the change will result in an
IllegalArgumentException
. If the new field is nested and its parent does not exist or is not a struct, the change will result in anIllegalArgumentException
.- Parameters:
fieldNames
- field names of the new columndataType
- the new column's data typeisNullable
- whether the new column can contain null- Returns:
- a TableChange for the addition
-
addColumn
static TableChange addColumn(String[] fieldNames, DataType dataType, boolean isNullable, String comment) Create a TableChange for adding a column.If the field already exists, the change will result in an
IllegalArgumentException
. If the new field is nested and its parent does not exist or is not a struct, the change will result in anIllegalArgumentException
.- Parameters:
fieldNames
- field names of the new columndataType
- the new column's data typeisNullable
- whether the new column can contain nullcomment
- the new field's comment string- Returns:
- a TableChange for the addition
-
addColumn
static TableChange addColumn(String[] fieldNames, DataType dataType, boolean isNullable, String comment, TableChange.ColumnPosition position, ColumnDefaultValue defaultValue) Create a TableChange for adding a column.If the field already exists, the change will result in an
IllegalArgumentException
. If the new field is nested and its parent does not exist or is not a struct, the change will result in anIllegalArgumentException
.- Parameters:
fieldNames
- field names of the new columndataType
- the new column's data typeisNullable
- whether the new column can contain nullcomment
- the new field's comment stringposition
- the new columns's positiondefaultValue
- default value to return when scanning from the new column, if any- Returns:
- a TableChange for the addition
-
renameColumn
Create a TableChange for renaming a field.The name is used to find the field to rename. The new name will replace the leaf field name. For example, renameColumn(["a", "b", "c"], "x") should produce column a.b.x.
If the field does not exist, the change will result in an
IllegalArgumentException
.- Parameters:
fieldNames
- the current field namesnewName
- the new name- Returns:
- a TableChange for the rename
-
updateColumnType
Create a TableChange for updating the type of a field that is nullable.The field names are used to find the field to update.
If the field does not exist, the change will result in an
IllegalArgumentException
.- Parameters:
fieldNames
- field names of the column to updatenewDataType
- the new data type- Returns:
- a TableChange for the update
-
updateColumnNullability
Create a TableChange for updating the nullability of a field.The name is used to find the field to update.
If the field does not exist, the change will result in an
IllegalArgumentException
.- Parameters:
fieldNames
- field names of the column to updatenullable
- the nullability- Returns:
- a TableChange for the update
-
updateColumnComment
Create a TableChange for updating the comment of a field.The name is used to find the field to update.
If the field does not exist, the change will result in an
IllegalArgumentException
.- Parameters:
fieldNames
- field names of the column to updatenewComment
- the new comment- Returns:
- a TableChange for the update
-
updateColumnPosition
static TableChange updateColumnPosition(String[] fieldNames, TableChange.ColumnPosition newPosition) Create a TableChange for updating the position of a field.The name is used to find the field to update.
If the field does not exist, the change will result in an
IllegalArgumentException
.- Parameters:
fieldNames
- field names of the column to updatenewPosition
- the new position- Returns:
- a TableChange for the update
-
updateColumnDefaultValue
Create a TableChange for updating the default value of a field.The name is used to find the field to update.
If the field does not exist, the change will result in an
IllegalArgumentException
.- Parameters:
fieldNames
- field names of the column to updatenewDefaultValue
- the new default value SQL string (Spark SQL dialect).- Returns:
- a TableChange for the update
-
deleteColumn
Create a TableChange for deleting a field.If the field does not exist, the change will result in an
IllegalArgumentException
.- Parameters:
fieldNames
- field names of the column to deleteifExists
- silence the error if column doesn't exist during drop- Returns:
- a TableChange for the delete
-