JingsongLi commented on code in PR #215:
URL: https://github.com/apache/flink-table-store/pull/215#discussion_r920816147
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/schema/SchemaManager.java:
##########
@@ -172,34 +175,48 @@ public TableSchema commitChanges(List<SchemaChange>
changes) throws Exception {
id, addColumn.fieldName(), dataType,
addColumn.description()));
} else if (change instanceof UpdateColumnType) {
UpdateColumnType update = (UpdateColumnType) change;
- boolean found = false;
- for (int i = 0; i < newFields.size(); i++) {
- DataField field = newFields.get(i);
- if (field.name().equals(update.fieldName())) {
- AtomicInteger dummyId = new AtomicInteger(0);
- DataType newType =
-
TableSchema.toDataType(update.newLogicalType(), dummyId);
- if (dummyId.get() != 0) {
- throw new RuntimeException(
- String.format(
- "Update column to nested row
type '%s' is not supported.",
- update.newLogicalType()));
- }
- newFields.set(
- i,
+ updateColumn(
+ newFields,
+ update.fieldName(),
+ (field) -> {
+ AtomicInteger dummyId = new AtomicInteger(0);
+ DataType newType =
+ TableSchema.toDataType(
+ update.newLogicalType(), new
AtomicInteger(0));
+ if (dummyId.get() != 0) {
+ throw new RuntimeException(
+ String.format(
+ "Update column to nested
row type '%s' is not supported.",
+ update.newLogicalType()));
+ }
+ return new DataField(field.id(), field.name(),
newType);
+ });
+ } else if (change instanceof UpdateColumnNullability) {
+ UpdateColumnNullability update = (UpdateColumnNullability)
change;
+ updateColumn(
+ newFields,
+ update.fieldName(),
+ (field) -> {
+ DataType newType =
+ TableSchema.toDataType(
+ field.type()
+ .logicalType()
+
.copy(update.newNullability()),
+ new AtomicInteger(0));
Review Comment:
If the type is a nested type, the fieldId will be wrong.
We can add a `copy(boolean isNullable)` to `DataType`.
--
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]