Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Aug 21, 2024
1 parent a55a267 commit fef1098
Showing 1 changed file with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public TableSchema commitChanges(List<SchemaChange> changes)
new Catalog.TableNotExistException(
identifierFromPath(
tableRoot.toString(), true, branch)));
Map<String, String> oldOptions = new HashMap<>(oldTableSchema.options());
Map<String, String> newOptions = new HashMap<>(oldTableSchema.options());
List<DataField> newFields = new ArrayList<>(oldTableSchema.fields());
AtomicInteger highestFieldId = new AtomicInteger(oldTableSchema.highestFieldId());
Expand All @@ -203,18 +204,17 @@ public TableSchema commitChanges(List<SchemaChange> changes)
if (change instanceof SetOption) {
SetOption setOption = (SetOption) change;
if (hasSnapshots) {
checkAlterTableOption(setOption.key());
if (setOption.key().equals(CoreOptions.BUCKET.key())) {
checkAlterBucket(
Integer.parseInt(newOptions.get(CoreOptions.BUCKET.key())),
Integer.parseInt(setOption.value()));
}
checkAlterTableOption(
setOption.key(),
oldOptions.get(setOption.key()),
setOption.value(),
false);
}
newOptions.put(setOption.key(), setOption.value());
} else if (change instanceof RemoveOption) {
RemoveOption removeOption = (RemoveOption) change;
if (hasSnapshots) {
checkAlterTableOption(removeOption.key());
checkResetTableOption(removeOption.key());
}
newOptions.remove(removeOption.key());
} else if (change instanceof UpdateComment) {
Expand Down Expand Up @@ -583,22 +583,44 @@ public void deleteSchema(long schemaId) {
fileIO.deleteQuietly(toSchemaPath(schemaId));
}

public static void checkAlterTableOption(String key) {
public static void checkAlterTableOption(
String key, @Nullable String oldValue, String newValue, boolean fromDynamicOptions) {
if (CoreOptions.IMMUTABLE_OPTIONS.contains(key)) {
throw new UnsupportedOperationException(
String.format("Change '%s' is not supported yet.", key));
}

if (CoreOptions.BUCKET.key().equals(key)) {
int oldBucket =
oldValue == null
? CoreOptions.BUCKET.defaultValue()
: Integer.parseInt(oldValue);
int newBucket = Integer.parseInt(newValue);
checkAlterBucket(oldBucket, newBucket, fromDynamicOptions);
}
}

public static void checkAlterBucket(int oldValue, int newValue) {
if (oldValue == newValue) {
return;
private static void checkAlterBucket(int oldValue, int newValue, boolean fromDynamicOptions) {
if (fromDynamicOptions) {
throw new UnsupportedOperationException(
"Cannot change bucket number through dynamic options. You might need to rescale bucket.");
}
if (oldValue == -1) {
throw new UnsupportedOperationException("Cannot change bucket to -1.");
throw new UnsupportedOperationException("Cannot change bucket when it is -1.");
}
if (newValue == -1) {
throw new UnsupportedOperationException("Cannot change bucket when it is -1.");
throw new UnsupportedOperationException("Cannot change bucket to -1.");
}
}

public static void checkResetTableOption(String key) {
if (CoreOptions.IMMUTABLE_OPTIONS.contains(key)) {
throw new UnsupportedOperationException(
String.format("Change '%s' is not supported yet.", key));
}

if (CoreOptions.BUCKET.key().equals(key)) {
throw new UnsupportedOperationException(String.format("Cannot reset %s.", key));
}
}

Expand Down

0 comments on commit fef1098

Please sign in to comment.