Skip to content

Commit 310a77d

Browse files
gyang94Liebing
authored andcommitted
fix: review
1 parent bd981d4 commit 310a77d

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

fluss-client/src/main/java/com/alibaba/fluss/client/admin/Admin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ CompletableFuture<Void> createTable(
240240
* <p>The following exceptions can be anticipated when calling {@code get()} on returned future.
241241
*
242242
* <ul>
243-
* <li>{@link DatabaseNotExistException} if the database does not exist.
243+
* <li>{@link DatabaseNotExistException} when the database does not exist.
244+
* <li>{@link TableNotExistException} when the table does not exist, if ignoreIfNotExists is
245+
* false.
244246
* </ul>
245247
*
246248
* @param tablePath The table path of the table.

fluss-client/src/test/java/com/alibaba/fluss/client/admin/FlussAdminITCase.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,69 @@ void testGetTableInfoAndSchema() throws Exception {
197197
.isBetween(timestampBeforeCreate, timestampAfterCreate);
198198
}
199199

200+
@Test
201+
void testAlterTable() throws Exception {
202+
// create table
203+
TablePath tablePath = TablePath.of("test_db", "alter_table_1");
204+
admin.createTable(tablePath, DEFAULT_TABLE_DESCRIPTOR, false).get();
205+
206+
TableInfo tableInfo = admin.getTableInfo(tablePath).get();
207+
208+
TableDescriptor existingTableDescriptor = tableInfo.toTableDescriptor();
209+
Map<String, String> updateProperties =
210+
new HashMap<>(existingTableDescriptor.getProperties());
211+
Map<String, String> updateCustomProperties =
212+
new HashMap<>(existingTableDescriptor.getCustomProperties());
213+
updateProperties.put("table.datalake.enabled", "true");
214+
updateCustomProperties.put("table.datalake.enabled", "true");
215+
216+
TableDescriptor newTableDescriptor =
217+
TableDescriptor.builder()
218+
.schema(existingTableDescriptor.getSchema())
219+
.comment(existingTableDescriptor.getComment().orElse("test table"))
220+
.partitionedBy(existingTableDescriptor.getPartitionKeys())
221+
.distributedBy(
222+
existingTableDescriptor
223+
.getTableDistribution()
224+
.get()
225+
.getBucketCount()
226+
.orElse(3),
227+
existingTableDescriptor.getBucketKeys())
228+
.properties(updateProperties)
229+
.customProperties(updateCustomProperties)
230+
.build();
231+
// alter table
232+
admin.alterTable(tablePath, newTableDescriptor, false).get();
233+
234+
TableInfo alteredTableInfo = admin.getTableInfo(tablePath).get();
235+
TableDescriptor alteredTableDescriptor = alteredTableInfo.toTableDescriptor();
236+
assertThat(alteredTableDescriptor).isEqualTo(newTableDescriptor);
237+
238+
// throw exception if table not exist
239+
assertThatThrownBy(
240+
() ->
241+
admin.alterTable(
242+
TablePath.of("test_db", "alter_table_not_exist"),
243+
newTableDescriptor,
244+
false)
245+
.get())
246+
.cause()
247+
.isInstanceOf(TableNotExistException.class);
248+
249+
// throw exception if database not exist
250+
assertThatThrownBy(
251+
() ->
252+
admin.alterTable(
253+
TablePath.of(
254+
"test_db_not_exist",
255+
"alter_table_not_exist"),
256+
newTableDescriptor,
257+
false)
258+
.get())
259+
.cause()
260+
.isInstanceOf(DatabaseNotExistException.class);
261+
}
262+
200263
@Test
201264
void testCreateInvalidDatabaseAndTable() {
202265
assertThatThrownBy(

fluss-flink/fluss-flink-common/src/main/java/com/alibaba/fluss/flink/catalog/FlinkCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public void alterTable(
399399
admin.alterTable(tablePath, tableDescriptor, ignoreIfNotExist).get();
400400
} catch (Exception e) {
401401
Throwable t = ExceptionUtils.stripExecutionException(e);
402-
if (CatalogExceptionUtils.isTableAlreadyExist(t)) {
402+
if (CatalogExceptionUtils.isTableNotExist(t)) {
403403
throw new TableNotExistException(getName(), objectPath);
404404
} else if (isTableInvalid(t)) {
405405
throw new InvalidTableException(t.getMessage());

fluss-rpc/src/main/proto/FlussApi.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ message AlterTableRequest {
116116
}
117117

118118
message AlterTableResponse {
119-
120119
}
121120

122121
// get table request and response

fluss-server/src/main/java/com/alibaba/fluss/server/coordinator/MetadataManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ public long createTable(
305305

306306
public void alterTable(
307307
TablePath tablePath, TableDescriptor tableDescriptor, boolean ignoreIfNotExists) {
308-
// validate table properties before creating table
309-
validateTableDescriptor(tableDescriptor, maxBucketNum);
308+
// validate table properties before altering table
309+
validateAlterTableProperties(tableDescriptor);
310310

311311
if (!databaseExists(tablePath.getDatabaseName())) {
312312
throw new DatabaseNotExistException(

0 commit comments

Comments
 (0)