Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1477,29 +1478,44 @@ 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
public void dropColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle column)
{
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
public void renameColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle source, String target)
{
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<ColumnMetadata> getColumnMetadatas(Schema schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Comment thread
nastra marked this conversation as resolved.
Outdated
}

Expand Down Expand Up @@ -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");
}

Expand Down