fsk119 commented on code in PR #21577:
URL: https://github.com/apache/flink/pull/21577#discussion_r1060254282
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/TableChange.java:
##########
@@ -276,6 +409,359 @@ public String toString() {
}
}
+ //
--------------------------------------------------------------------------------------------
+ // Modify Change
+ //
--------------------------------------------------------------------------------------------
+
+ /**
+ * A base schema change to modify a column. The modification includes:
+ *
+ * <ul>
+ * <li>change column data type
+ * <li>reorder column position
+ * <li>modify column comment
+ * <li>change the computed expression
+ * </ul>
+ *
+ * <p>Some fine-grained column changes are defined in the {@link
ModifyPhysicalColumnType},
+ * {@link ModifyColumnComment}, {@link ModifyColumnPosition} and {@link
ModifyColumnName}.
+ *
+ * <p>It is equal to the following statement:
+ *
+ * <pre>
+ * ALTER TABLE <table_name> MODIFY <column_definition>
COMMENT '<column_comment>' <column_position>
+ * </pre>
+ */
+ @PublicEvolving
+ class ModifyColumn implements TableChange {
+
+ protected final Column oldColumn;
+ protected final Column newColumn;
+
+ protected final @Nullable ColumnPosition newPosition;
+
+ public ModifyColumn(
+ Column oldColumn, Column newColumn, @Nullable ColumnPosition
newPosition) {
+ this.oldColumn = oldColumn;
+ this.newColumn = newColumn;
+ this.newPosition = newPosition;
+ }
+
+ /** Returns the original {@link Column} instance. */
+ public Column getOldColumn() {
+ return oldColumn;
+ }
+
+ /** Returns the modified {@link Column} instance. */
+ public Column getNewColumn() {
+ return newColumn;
+ }
+
+ /**
+ * Returns the position of the modified {@link Column} instance. When
the return value is
+ * null, it means modify the column at the original position. When the
return value is
+ * FIRST, it means move the modified column to the first. When the
return value is AFTER, it
+ * means move the column after the referred column.
+ */
+ public @Nullable ColumnPosition getNewPosition() {
+ return newPosition;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof ModifyColumn)) {
+ return false;
+ }
+ ModifyColumn that = (ModifyColumn) o;
+ return Objects.equals(oldColumn, that.oldColumn)
+ && Objects.equals(newColumn, that.newColumn)
+ && Objects.equals(newPosition, that.newPosition);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(oldColumn, newColumn, newPosition);
+ }
+
+ @Override
+ public String toString() {
+ return "ModifyColumn{"
+ + "oldColumn="
+ + oldColumn
+ + ", newColumn="
+ + newColumn
+ + ", newPosition="
+ + newPosition
+ + '}';
+ }
+ }
+
+ /**
+ * A table change to modify the column comment.
+ *
+ * <p>It is equal to the following statement:
+ *
+ * <pre>
+ * ALTER TABLE <table_name> MODIFY <column_name>
<original_column_type> COMMENT '<new_column_comment>'
+ * </pre>
+ */
+ @PublicEvolving
+ class ModifyColumnComment extends ModifyColumn {
+
+ private final String newComment;
+
+ private ModifyColumnComment(Column oldColumn, String newComment) {
+ super(oldColumn, oldColumn.withComment(newComment), null);
+ this.newComment = newComment;
+ }
+
+ /** Get the new comment for the column. */
+ public String getNewComment() {
+ return newComment;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return (o instanceof ModifyColumnComment) && super.equals(o);
+ }
+
+ @Override
+ public String toString() {
+ return "ModifyColumnComment{"
+ + "Column="
+ + oldColumn
+ + ", newComment='"
+ + newComment
+ + '\''
+ + '}';
+ }
+ }
+
+ /**
+ * A table change to modify the column position.
+ *
+ * <p>It is equal to the following statement:
+ *
+ * <pre>
+ * ALTER TABLE <table_name> MODIFY <column_name>
<original_column_type> <column_position>
+ * </pre>
+ */
+ @PublicEvolving
+ class ModifyColumnPosition extends ModifyColumn {
+
+ public ModifyColumnPosition(Column oldColumn, ColumnPosition
newPosition) {
+ super(oldColumn, oldColumn, newPosition);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return (o instanceof ModifyColumnPosition) && super.equals(o);
+ }
+
+ @Override
+ public String toString() {
+ return "ModifyColumnPosition{"
+ + "Column="
+ + oldColumn
+ + ", newPosition="
+ + newPosition
+ + '}';
+ }
+ }
+
+ /**
+ * A table change that modify the physical column data type.
Review Comment:
No. If users want to support modifying the metadata column type, we should
introduce another class named `ModifyMetadataColumn`, which may also involve
the change of the metadata key.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]