tsreaper commented on code in PR #347:
URL: https://github.com/apache/flink-table-store/pull/347#discussion_r1013789950
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/schema/SchemaManager.java:
##########
@@ -191,6 +193,49 @@ public TableSchema commitChanges(List<SchemaChange>
changes) throws Exception {
newFields.add(
new DataField(
id, addColumn.fieldName(), dataType,
addColumn.description()));
+ } else if (change instanceof RenameColumn) {
+ RenameColumn rename = (RenameColumn) change;
+ if (schema.partitionKeys().contains(rename.fieldName())) {
+ throw new UnsupportedOperationException("Cannot rename
partition key");
+ }
+ if (newFields.stream()
+ .anyMatch(
+ f ->
+ StringUtils.equalsIgnoreCase(
+ f.name(),
rename.newName()))) {
+ throw new IllegalArgumentException(
+ String.format(
+ "The column [%s] exists in the
table[%s].",
+ rename.newName(), tableRoot));
+ }
+
+ updateNestedColumn(
+ newFields,
+ new String[] {rename.fieldName()},
+ 0,
+ (field) ->
+ new DataField(
+ field.id(),
+ rename.newName(),
+ field.type(),
+ field.description()));
+ } else if (change instanceof DropColumn) {
+ DropColumn drop = (DropColumn) change;
+ if (schema.partitionKeys().contains(drop.fieldName())) {
+ throw new UnsupportedOperationException("Cannot drop
partition key");
+ }
+ if (schema.primaryKeys().contains(drop.fieldName())) {
+ throw new UnsupportedOperationException("Cannot drop
primary key");
+ }
+ if (!newFields.removeIf(
+ f ->
+ StringUtils.equalsIgnoreCase(
+ f.name(), ((DropColumn)
change).fieldName()))) {
+ throw new IllegalArgumentException(
+ String.format(
+ "The column [%s] doesn't exist in the
table[%s].",
+ drop.fieldName(), tableRoot));
+ }
Review Comment:
Consider a table without partition keys and primary keys (for example, an
append-only table). It seems that we can drop all columns of this table, which
is obviously undesired. Fix this case and add a test.
--
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]