Skip to content

Commit 5b84f34

Browse files
authored
Core: Don't fail if a REST service doesn't support views (apache#9754)
1 parent 4c5208a commit 5b84f34

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

api/src/main/java/org/apache/iceberg/exceptions/BadRequestException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import com.google.errorprone.annotations.FormatMethod;
2222

2323
/** Exception thrown on HTTP 400 - Bad Request */
24-
public class BadRequestException extends RuntimeException implements CleanableFailure {
24+
public class BadRequestException extends RESTException implements CleanableFailure {
2525
@FormatMethod
2626
public BadRequestException(String message, Object... args) {
27-
super(String.format(message, args));
27+
super(message, args);
2828
}
2929

3030
@FormatMethod
3131
public BadRequestException(Throwable cause, String message, Object... args) {
32-
super(String.format(message, args), cause);
32+
super(cause, message, args);
3333
}
3434
}

api/src/main/java/org/apache/iceberg/exceptions/ForbiddenException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import com.google.errorprone.annotations.FormatMethod;
2222

2323
/** Exception thrown on HTTP 403 Forbidden - Failed authorization checks. */
24-
public class ForbiddenException extends RuntimeException implements CleanableFailure {
24+
public class ForbiddenException extends RESTException implements CleanableFailure {
2525
@FormatMethod
2626
public ForbiddenException(String message, Object... args) {
27-
super(String.format(message, args));
27+
super(message, args);
2828
}
2929

3030
@FormatMethod
3131
public ForbiddenException(Throwable cause, String message, Object... args) {
32-
super(String.format(message, args), cause);
32+
super(cause, message, args);
3333
}
3434
}

core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
6060
import org.apache.iceberg.exceptions.NoSuchTableException;
6161
import org.apache.iceberg.exceptions.NoSuchViewException;
62+
import org.apache.iceberg.exceptions.RESTException;
6263
import org.apache.iceberg.hadoop.Configurable;
6364
import org.apache.iceberg.io.CloseableGroup;
6465
import org.apache.iceberg.io.FileIO;
@@ -717,8 +718,15 @@ public Transaction createTransaction() {
717718

718719
@Override
719720
public Transaction replaceTransaction() {
720-
if (viewExists(context, ident)) {
721-
throw new AlreadyExistsException("View with same name already exists: %s", ident);
721+
try {
722+
if (viewExists(context, ident)) {
723+
throw new AlreadyExistsException("View with same name already exists: %s", ident);
724+
}
725+
} catch (RESTException | UnsupportedOperationException e) {
726+
// don't fail if the server doesn't support views, which could be due to:
727+
// 1. server or backing catalog doesn't support views
728+
// 2. newer client talks to an older server that doesn't support views
729+
LOG.debug("Failed to check whether view {} exists", ident, e);
722730
}
723731

724732
LoadTableResponse response = loadInternal(context, ident, snapshotMode);

0 commit comments

Comments
 (0)