Skip to content

Commit ee8d1c3

Browse files
committed
[paimon] Align error msg when altering table properties
1 parent f02bcdf commit ee8d1c3

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

fluss-lake/fluss-lake-paimon/src/main/java/org/apache/fluss/lake/paimon/PaimonLakeCatalog.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ public void createTable(TablePath tablePath, TableDescriptor tableDescriptor, Co
109109
public void alterTable(TablePath tablePath, List<TableChange> tableChanges, Context context)
110110
throws TableNotExistException {
111111
try {
112-
Identifier paimonPath = toPaimon(tablePath);
113112
List<SchemaChange> paimonSchemaChanges = toPaimonSchemaChanges(tableChanges);
114-
alterTable(paimonPath, paimonSchemaChanges);
113+
alterTable(tablePath, paimonSchemaChanges);
115114
} catch (Catalog.ColumnAlreadyExistException | Catalog.ColumnNotExistException e) {
116115
// shouldn't happen before we support schema change
117116
throw new RuntimeException(e);
@@ -155,12 +154,12 @@ private void createDatabase(String databaseName) {
155154
}
156155
}
157156

158-
private void alterTable(Identifier tablePath, List<SchemaChange> tableChanges)
157+
private void alterTable(TablePath tablePath, List<SchemaChange> tableChanges)
159158
throws Catalog.ColumnAlreadyExistException, Catalog.ColumnNotExistException {
160159
try {
161-
paimonCatalog.alterTable(tablePath, tableChanges, false);
160+
paimonCatalog.alterTable(toPaimon(tablePath), tableChanges, false);
162161
} catch (Catalog.TableNotExistException e) {
163-
throw new TableNotExistException("Table " + tablePath + " not exists.");
162+
throw new TableNotExistException("Table " + tablePath + " does not exist.");
164163
}
165164
}
166165

fluss-lake/fluss-lake-paimon/src/test/java/org/apache/fluss/lake/paimon/PaimonLakeCatalogTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.fluss.lake.paimon;
1919

2020
import org.apache.fluss.config.Configuration;
21+
import org.apache.fluss.exception.TableNotExistException;
2122
import org.apache.fluss.lake.lakestorage.TestingLakeCatalogContext;
2223
import org.apache.fluss.metadata.Schema;
2324
import org.apache.fluss.metadata.TableChange;
@@ -35,6 +36,7 @@
3536
import java.util.Collections;
3637

3738
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3840

3941
/** Unit test for {@link PaimonLakeCatalog}. */
4042
class PaimonLakeCatalogTest {
@@ -83,6 +85,34 @@ void testAlterTableProperties() throws Exception {
8385
assertThat(table.options().get("fluss.key")).isEqualTo(null);
8486
}
8587

88+
@Test
89+
void alterTablePropertiesWithNonExistentTable() {
90+
TestingLakeCatalogContext context = new TestingLakeCatalogContext();
91+
// db & table don't exist
92+
assertThatThrownBy(
93+
() ->
94+
flussPaimonCatalog.alterTable(
95+
TablePath.of("non_existing_db", "non_existing_table"),
96+
Collections.singletonList(TableChange.set("key", "value")),
97+
context))
98+
.isInstanceOf(TableNotExistException.class)
99+
.hasMessage("Table non_existing_db.non_existing_table does not exist.");
100+
101+
String database = "alter_props_db";
102+
String tableName = "alter_props_table";
103+
createTable(database, tableName);
104+
105+
// database exists but table doesn't
106+
assertThatThrownBy(
107+
() ->
108+
flussPaimonCatalog.alterTable(
109+
TablePath.of(database, "non_existing_table"),
110+
Collections.singletonList(TableChange.set("key", "value")),
111+
context))
112+
.isInstanceOf(TableNotExistException.class)
113+
.hasMessage("Table alter_props_db.non_existing_table does not exist.");
114+
}
115+
86116
private void createTable(String database, String tableName) {
87117
Schema flussSchema =
88118
Schema.newBuilder()

0 commit comments

Comments
 (0)