Skip to content

Commit b0a4124

Browse files
authored
[paimon] Align error msg when altering table properties (#2046)
1 parent a429170 commit b0a4124

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,14 @@ protected Catalog getPaimonCatalog() {
8484
public void createTable(TablePath tablePath, TableDescriptor tableDescriptor, Context context)
8585
throws TableAlreadyExistException {
8686
// then, create the table
87-
Identifier paimonPath = toPaimon(tablePath);
8887
Schema paimonSchema = toPaimonSchema(tableDescriptor);
8988
try {
90-
createTable(paimonPath, paimonSchema, context.isCreatingFlussTable());
89+
createTable(tablePath, paimonSchema, context.isCreatingFlussTable());
9190
} catch (Catalog.DatabaseNotExistException e) {
9291
// create database
9392
createDatabase(tablePath.getDatabaseName());
9493
try {
95-
createTable(paimonPath, paimonSchema, context.isCreatingFlussTable());
94+
createTable(tablePath, paimonSchema, context.isCreatingFlussTable());
9695
} catch (Catalog.DatabaseNotExistException t) {
9796
// shouldn't happen in normal cases
9897
throw new RuntimeException(
@@ -109,26 +108,26 @@ public void createTable(TablePath tablePath, TableDescriptor tableDescriptor, Co
109108
public void alterTable(TablePath tablePath, List<TableChange> tableChanges, Context context)
110109
throws TableNotExistException {
111110
try {
112-
Identifier paimonPath = toPaimon(tablePath);
113111
List<SchemaChange> paimonSchemaChanges = toPaimonSchemaChanges(tableChanges);
114-
alterTable(paimonPath, paimonSchemaChanges);
112+
alterTable(tablePath, paimonSchemaChanges);
115113
} catch (Catalog.ColumnAlreadyExistException | Catalog.ColumnNotExistException e) {
116114
// shouldn't happen before we support schema change
117115
throw new RuntimeException(e);
118116
}
119117
}
120118

121-
private void createTable(Identifier tablePath, Schema schema, boolean isCreatingFlussTable)
119+
private void createTable(TablePath tablePath, Schema schema, boolean isCreatingFlussTable)
122120
throws Catalog.DatabaseNotExistException {
121+
Identifier paimonPath = toPaimon(tablePath);
123122
try {
124123
// not ignore if table exists
125-
paimonCatalog.createTable(tablePath, schema, false);
124+
paimonCatalog.createTable(paimonPath, schema, false);
126125
} catch (Catalog.TableAlreadyExistException e) {
127126
try {
128-
Table table = paimonCatalog.getTable(tablePath);
127+
Table table = paimonCatalog.getTable(paimonPath);
129128
FileStoreTable fileStoreTable = (FileStoreTable) table;
130129
validatePaimonSchemaCompatible(
131-
tablePath, fileStoreTable.schema().toSchema(), schema);
130+
paimonPath, fileStoreTable.schema().toSchema(), schema);
132131
// if creating a new fluss table, we should ensure the lake table is empty
133132
if (isCreatingFlussTable) {
134133
checkTableIsEmpty(tablePath, fileStoreTable);
@@ -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/main/java/org/apache/fluss/lake/paimon/utils/PaimonTableValidation.java

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

2020
import org.apache.fluss.exception.TableAlreadyExistException;
21+
import org.apache.fluss.metadata.TablePath;
2122

2223
import org.apache.paimon.CoreOptions;
2324
import org.apache.paimon.catalog.Identifier;
@@ -79,13 +80,13 @@ private static void removeChangeableOptions(Map<String, String> options) {
7980
&& !entry.getKey().startsWith(FLUSS_CONF_PREFIX));
8081
}
8182

82-
public static void checkTableIsEmpty(Identifier tablePath, FileStoreTable table) {
83+
public static void checkTableIsEmpty(TablePath tablePath, FileStoreTable table) {
8384
if (table.latestSnapshot().isPresent()) {
8485
throw new TableAlreadyExistException(
8586
String.format(
8687
"The table %s already exists in Paimon catalog, and the table is not empty. "
8788
+ "Please first drop the table in Paimon catalog or use a new table name.",
88-
tablePath.getEscapedFullName()));
89+
tablePath));
8990
}
9091
}
9192

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void testCreateLakeEnableTableWithExistNonEmptyLakeTable() throws Exception {
561561
.cause()
562562
.isInstanceOf(LakeTableAlreadyExistException.class)
563563
.hasMessage(
564-
"The table `fluss`.`log_table_with_non_empty_lake_table` already exists in Paimon catalog, and the table is not empty. Please first drop the table in Paimon catalog or use a new table name.");
564+
"The table fluss.log_table_with_non_empty_lake_table already exists in Paimon catalog, and the table is not empty. Please first drop the table in Paimon catalog or use a new table name.");
565565
}
566566

567567
@Test

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)