#13924: in Iceberg catalog, JdbcTableOperations should catch and handle PostgresSQL's exception for duplicated keys#15434
Open
sqd wants to merge 1 commit intoapache:mainfrom
Open
#13924: in Iceberg catalog, JdbcTableOperations should catch and handle PostgresSQL's exception for duplicated keys#15434sqd wants to merge 1 commit intoapache:mainfrom
sqd wants to merge 1 commit intoapache:mainfrom
Conversation
| // SQLite doesn't set SQLState or throw SQLIntegrityConstraintViolationException | ||
| if (e.getMessage() != null && e.getMessage().contains("constraint failed")) { | ||
| // Postgres doesn't throw SQLIntegrityConstraintViolationException but sets SQLState to | ||
| // "23505" (unique violation) |
Member
There was a problem hiding this comment.
Don't we need a similar fix in ViewOperations?
JDBCCatalog has a similar check in renameTable and renameView
It may be best to pull this bit of logic out into a utility method and ditch the magic string.
static boolean isConstraintViolation(SQLException e) {
return e instanceof SQLIntegrityConstraintViolationException
|| POSTGRES_UNIQUE_VIOLATION_SQLSTATE.equals(e.getSQLState())
|| (e.getMessage() != null && e.getMessage().contains("constraint failed"));
}
static void handleCommitSqlException(
SQLException e, String currentMetadataLocation, String entityType, Object identifier) {
if (isConstraintViolation(e)) {
if (currentMetadataLocation == null) {
throw new AlreadyExistsException(e, "%s already exists: %s", entityType, identifier);
} else {
throw new UncheckedSQLException(e, "%s already exists: %s", entityType, identifier);
}
}
throw new UncheckedSQLException(e, "Unknown failure");
}We also need a test of the new pathway, should be a pretty simple mock I think?
Author
There was a problem hiding this comment.
Good point. I extrapolated that out and added a few tests.
76e9dee to
e7ab9c8
Compare
e7ab9c8 to
b6107de
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13924
Previously reviewed at #13925 (fixed all the suggestions in there)