Skip to content

Commit

Permalink
fix the bug #3083,support recreat the hive table
Browse files Browse the repository at this point in the history
  • Loading branch information
liuw529 committed Mar 24, 2024
1 parent 92cb24b commit d3d9047
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -124,16 +125,28 @@ public List<Long> listAllIds() {
}
}

/** Check TableScheme is be modified. */
public void checkTableSchema(TableSchema oldSchema, TableSchema newSchema) {
boolean isCommon =
oldSchema.version() == newSchema.version()
&& oldSchema.id() == newSchema.id()
&& Objects.equals(oldSchema.fields(), newSchema.fields())
&& oldSchema.highestFieldId() == newSchema.highestFieldId()
&& Objects.equals(oldSchema.partitionKeys(), newSchema.partitionKeys())
&& Objects.equals(oldSchema.primaryKeys(), newSchema.primaryKeys())
&& Objects.equals(oldSchema.options(), newSchema.options());

if (!isCommon) {
throw new IllegalStateException(
"Schema in filesystem exists, please use updating,"
+ " latest schema is: "
+ oldSchema);
}
}

/** Create a new schema from {@link Schema}. */
public TableSchema createTable(Schema schema) throws Exception {
while (true) {
latest().ifPresent(
latest -> {
throw new IllegalStateException(
"Schema in filesystem exists, please use updating,"
+ " latest schema is: "
+ latest());
});

List<DataField> fields = schema.fields();
List<String> partitionKeys = schema.partitionKeys();
Expand All @@ -151,6 +164,11 @@ public TableSchema createTable(Schema schema) throws Exception {
options,
schema.comment());

if (latest().isPresent()) {
checkTableSchema(latest().get(), newSchema);
return newSchema;
}

boolean success = commit(newSchema);
if (success) {
return newSchema;
Expand Down

0 comments on commit d3d9047

Please sign in to comment.