diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java index e9eec1869909..d0f6ca66fef0 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java @@ -160,6 +160,7 @@ import java.util.regex.Pattern; import java.util.stream.Stream; +import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Verify.verify; @@ -1477,9 +1478,14 @@ public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle throw new TrinoException(NOT_SUPPORTED, "This connector does not support adding not null columns"); } Table icebergTable = catalog.loadTable(session, ((IcebergTableHandle) tableHandle).getSchemaTableName()); - icebergTable.updateSchema() - .addColumn(column.getName(), toIcebergType(column.getType()), column.getComment()) - .commit(); + try { + icebergTable.updateSchema() + .addColumn(column.getName(), toIcebergType(column.getType()), column.getComment()) + .commit(); + } + catch (RuntimeException e) { + throw new TrinoException(ICEBERG_COMMIT_ERROR, "Failed to add column: " + firstNonNull(e.getMessage(), e), e); + } } @Override @@ -1487,9 +1493,14 @@ public void dropColumn(ConnectorSession session, ConnectorTableHandle tableHandl { IcebergColumnHandle handle = (IcebergColumnHandle) column; Table icebergTable = catalog.loadTable(session, ((IcebergTableHandle) tableHandle).getSchemaTableName()); - icebergTable.updateSchema() - .deleteColumn(handle.getName()) - .commit(); + try { + icebergTable.updateSchema() + .deleteColumn(handle.getName()) + .commit(); + } + catch (RuntimeException e) { + throw new TrinoException(ICEBERG_COMMIT_ERROR, "Failed to drop column: " + firstNonNull(e.getMessage(), e), e); + } } @Override @@ -1497,9 +1508,14 @@ public void renameColumn(ConnectorSession session, ConnectorTableHandle tableHan { IcebergColumnHandle columnHandle = (IcebergColumnHandle) source; Table icebergTable = catalog.loadTable(session, ((IcebergTableHandle) tableHandle).getSchemaTableName()); - icebergTable.updateSchema() - .renameColumn(columnHandle.getName(), target) - .commit(); + try { + icebergTable.updateSchema() + .renameColumn(columnHandle.getName(), target) + .commit(); + } + catch (RuntimeException e) { + throw new TrinoException(ICEBERG_COMMIT_ERROR, "Failed to rename column: " + firstNonNull(e.getMessage(), e), e); + } } private List getColumnMetadatas(Schema schema) diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java index 0b7de62d1a32..d4bd59bfaa79 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java @@ -204,7 +204,7 @@ public void testAddAndDropColumnName(String columnName) { if (columnName.equals("a.dot")) { assertThatThrownBy(() -> super.testAddAndDropColumnName(columnName)) - .hasMessageContaining("Cannot add column with ambiguous name"); + .hasMessage("Failed to add column: Cannot add column with ambiguous name: a.dot, use addColumn(parent, name, type)"); return; } super.testAddAndDropColumnName(columnName); @@ -231,6 +231,8 @@ protected void verifyConcurrentUpdateFailurePermissible(Exception e) protected void verifyConcurrentAddColumnFailurePermissible(Exception e) { assertThat(e) + .hasMessageStartingWith("Failed to add column: Failed to replace table due to concurrent updates") + .getRootCause() .hasMessageContaining("Cannot update Iceberg table: supplied previous location does not match current location"); } @@ -4428,12 +4430,12 @@ public void testAmbiguousColumnsWithDots() assertUpdate("CREATE TABLE ambiguous (\"a.cow\" BIGINT, b ROW(cow BIGINT))"); assertThatThrownBy(() -> assertUpdate("ALTER TABLE ambiguous RENAME COLUMN b TO a")) - .hasMessage("Invalid schema: multiple fields for name a.cow: 1 and 3"); + .hasMessage("Failed to rename column: Invalid schema: multiple fields for name a.cow: 1 and 3"); assertUpdate("DROP TABLE ambiguous"); assertUpdate("CREATE TABLE ambiguous (a ROW(cow BIGINT))"); assertThatThrownBy(() -> assertUpdate("ALTER TABLE ambiguous ADD COLUMN \"a.cow\" BIGINT")) - .hasMessage("Cannot add column with ambiguous name: a.cow, use addColumn(parent, name, type)"); + .hasMessage("Failed to add column: Cannot add column with ambiguous name: a.cow, use addColumn(parent, name, type)"); assertUpdate("DROP TABLE ambiguous"); }