Skip to content

Commit 52f1b61

Browse files
rdblue钟宇江
authored andcommitted
Core: Fix REST catalog handling when the service has no view support (apache#9853)
* Core: Fix REST catalog handling when the service has no view support. * Fix error message. * Improve the error message. (cherry picked from commit 1a4f23b)
1 parent fad47e6 commit 52f1b61

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

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

Lines changed: 26 additions & 8 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;
@@ -678,8 +679,15 @@ public Transaction createTransaction() {
678679

679680
@Override
680681
public Transaction replaceTransaction() {
681-
if (viewExists(context, ident)) {
682-
throw new AlreadyExistsException("View with same name already exists: %s", ident);
682+
try {
683+
if (viewExists(context, ident)) {
684+
throw new AlreadyExistsException("View with same name already exists: %s", ident);
685+
}
686+
} catch (RESTException | UnsupportedOperationException e) {
687+
// don't fail if the server doesn't support views, which could be due to:
688+
// 1. server or backing catalog doesn't support views
689+
// 2. newer client talks to an older server that doesn't support views
690+
LOG.debug("Failed to check whether view {} exists", ident, e);
683691
}
684692

685693
LoadTableResponse response = loadInternal(context, ident, snapshotMode);
@@ -974,12 +982,22 @@ public List<TableIdentifier> listViews(SessionContext context, Namespace namespa
974982
public View loadView(SessionContext context, TableIdentifier identifier) {
975983
checkViewIdentifierIsValid(identifier);
976984

977-
LoadViewResponse response =
978-
client.get(
979-
paths.view(identifier),
980-
LoadViewResponse.class,
981-
headers(context),
982-
ErrorHandlers.viewErrorHandler());
985+
LoadViewResponse response;
986+
try {
987+
response =
988+
client.get(
989+
paths.view(identifier),
990+
LoadViewResponse.class,
991+
headers(context),
992+
ErrorHandlers.viewErrorHandler());
993+
} catch (UnsupportedOperationException | RESTException e) {
994+
// Normally, copying an exception message is a bad practice but engines may show just the
995+
// message and suppress the exception cause when the view does not exist. Since 401 and 403
996+
// responses can trigger this case, including the message increases the chances that the "Not
997+
// authorized" or "Forbidden" message is preserved and shown.
998+
throw new NoSuchViewException(
999+
e, "Unable to load view %s.%s: %s", name(), identifier, e.getMessage());
1000+
}
9831001

9841002
AuthSession session = tableSession(response.config(), session(context));
9851003
ViewMetadata metadata = response.metadata();

spark/v3.3/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestDelete.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import org.apache.iceberg.relocated.com.google.common.util.concurrent.MoreExecutors;
5858
import org.apache.iceberg.spark.Spark3Util;
5959
import org.apache.iceberg.spark.data.TestHelpers;
60-
import org.apache.spark.SparkException;
6160
import org.apache.spark.sql.AnalysisException;
6261
import org.apache.spark.sql.Dataset;
6362
import org.apache.spark.sql.Encoders;
@@ -928,7 +927,6 @@ public synchronized void testDeleteWithSerializableIsolation() throws Interrupte
928927
Assert.fail("Expected a validation exception");
929928
} catch (ExecutionException e) {
930929
Throwable sparkException = e.getCause();
931-
Assert.assertThat(sparkException, CoreMatchers.instanceOf(SparkException.class));
932930
Throwable validationException = sparkException.getCause();
933931
Assert.assertThat(validationException, CoreMatchers.instanceOf(ValidationException.class));
934932
String errMsg = validationException.getMessage();

0 commit comments

Comments
 (0)