Skip to content

Commit

Permalink
[core] new column exception shows the specific column name (apache#2746)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangchong authored Jan 20, 2024
1 parent 52d0aa2 commit e26e6b5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/content/program-api/java-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public class RenameTable {

You can use the catalog to alter a table, but you need to pay attention to the following points.

- Add column cannot specify NOT NULL.
- Column %s cannot specify NOT NULL in the %s table.
- Cannot update partition column type in the table.
- Cannot change nullability of primary key.
- If the type of the column is nested row type, update the column type is not supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ public TableSchema commitChanges(List<SchemaChange> changes)
}
Preconditions.checkArgument(
addColumn.dataType().isNullable(),
"ADD COLUMN cannot specify NOT NULL.");
"Column %s cannot specify NOT NULL in the %s table.",
addColumn.fieldName(),
fromPath(tableRoot.toString(), true).getFullName());
int id = highestFieldId.incrementAndGet();
DataType dataType =
ReassignFieldId.reassign(addColumn.dataType(), highestFieldId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ public void testAddField() throws Exception {
null,
null))))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("ADD COLUMN cannot specify NOT NULL.");
.hasMessage(
String.format(
"Column %s cannot specify NOT NULL in the %s table.",
"f4", identifier.getFullName()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ public static Schema buildPaimonSchema(
for (String key : specifiedPrimaryKeys) {
checkArgument(
sourceColumns.contains(key),
"Specified primary key '%s' does not exist in source tables or computed columns.",
key);
"Specified primary key '%s' does not exist in source tables or computed columns %s.",
key,
sourceColumns);
}
builder.primaryKey(listCaseConvert(specifiedPrimaryKeys, caseSensitive));
} else if (!sourceSchema.primaryKeys().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public void testInvalidPrimaryKey() {
.satisfies(
anyCauseMatches(
IllegalArgumentException.class,
"Specified primary key 'pk' does not exist in source tables or computed columns."));
"Specified primary key 'pk' does not exist in source tables or computed columns [pt, _id, v1]."));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testAddNotNullColumn() {
.satisfies(
anyCauseMatches(
IllegalArgumentException.class,
"ADD COLUMN cannot specify NOT NULL."));
"Column d cannot specify NOT NULL in the default.testAddNotNullColumn table."));
}

@Test
Expand Down

0 comments on commit e26e6b5

Please sign in to comment.