Interface TableChange
- All Known Subinterfaces:
TableChange.ColumnChange
- All Known Implementing Classes:
TableChange.AddColumn,TableChange.AddConstraint,TableChange.ClusterBy,TableChange.DeleteColumn,TableChange.DropConstraint,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
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classA TableChange to add a field.static final classA TableChange to alter table and add a constraint.static final classColumn position AFTER means the specified column should be put after the given `column`.static final classA TableChange to alter clustering columns for a table.static interfacestatic interfacestatic final classA TableChange to delete a field.static final classA TableChange to alter table and drop a constraint.static final classColumn position FIRST means the specified column should be the first column.static final classA TableChange to remove a table property.static final classA TableChange to rename a field.static final classA TableChange to set a table property.static final classA TableChange to update the comment of a field.static final classA TableChange to update the default value of a field.static final classA TableChange to update the nullability of a field.static final classA TableChange to update the position of a field.static final classA TableChange to update the type of a field. -
Method Summary
Modifier and TypeMethodDescriptionstatic TableChangeCreate a TableChange for adding an optional column.static TableChangeCreate a TableChange for adding a column.static TableChangeCreate a TableChange for adding a column.static TableChangeaddColumn(String[] fieldNames, DataType dataType, boolean isNullable, String comment, TableChange.ColumnPosition position, ColumnDefaultValue defaultValue) Create a TableChange for adding a column.static TableChangeaddConstraint(Constraint constraint, String validatedTableVersion) Create a TableChange for adding a new table constraintstatic TableChangeclusterBy(NamedReference[] clusteringColumns) Create a TableChange for changing clustering columns for a table.static TableChangedeleteColumn(String[] fieldNames, Boolean ifExists) Create a TableChange for deleting a field.static TableChangedropConstraint(String name, boolean ifExists, boolean cascade) Create a TableChange for dropping a table constraintstatic TableChangeremoveProperty(String property) Create a TableChange for removing a table property.static TableChangerenameColumn(String[] fieldNames, String newName) Create a TableChange for renaming a field.static TableChangesetProperty(String property, String value) Create a TableChange for setting a table property.static TableChangeupdateColumnComment(String[] fieldNames, String newComment) Create a TableChange for updating the comment of a field.static TableChangeupdateColumnDefaultValue(String[] fieldNames, String newDefaultValue) Deprecated.static TableChangeupdateColumnDefaultValue(String[] fieldNames, DefaultValue newDefaultValue) Create a TableChange for updating the default value of a field.static TableChangeupdateColumnNullability(String[] fieldNames, boolean nullable) Create a TableChange for updating the nullability of a field.static TableChangeupdateColumnPosition(String[] fieldNames, TableChange.ColumnPosition newPosition) Create a TableChange for updating the position of a field.static TableChangeupdateColumnType(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
@Deprecated(since="4.1.0") static TableChange updateColumnDefaultValue(String[] fieldNames, String newDefaultValue) Deprecated.Please useupdateColumnDefaultValue(String[], DefaultValue)instead.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
-
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 (Spark SQL dialect and V2 expression representation if it can be converted). Null indicates dropping column default value- 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
-
clusterBy
Create a TableChange for changing clustering columns for a table.- Parameters:
clusteringColumns- clustering columns to change to. Each clustering column represents field names.- Returns:
- a TableChange for this assignment
-
addConstraint
Create a TableChange for adding a new table constraint -
dropConstraint
Create a TableChange for dropping a table constraint
-
updateColumnDefaultValue(String[], DefaultValue)instead.