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 @@ -1116,6 +1116,10 @@ public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle
DeltaLakeTableHandle handle = (DeltaLakeTableHandle) tableHandle;
checkSupportedWriterVersion(session, handle.getSchemaTableName());

if (!newColumnMetadata.isNullable() && !metastore.getValidDataFiles(handle.getSchemaTableName(), session).isEmpty()) {
throw new TrinoException(DELTA_LAKE_BAD_WRITE, format("Unable to add NOT NULL column '%s' for non-empty table: %s.%s", newColumnMetadata.getName(), handle.getSchemaName(), handle.getTableName()));
}

ConnectorTableMetadata tableMetadata = getTableMetadata(session, handle);

try {
Expand All @@ -1137,10 +1141,6 @@ public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle
columnsNullability.putAll(getColumnsNullability(handle.getMetadataEntry()));
columnsNullability.put(newColumnMetadata.getName(), newColumnMetadata.isNullable());

ImmutableMap.Builder<String, Boolean> columnNullability = ImmutableMap.builder();
columnNullability.putAll(getColumnsNullability(handle.getMetadataEntry()));
columnNullability.put(newColumnMetadata.getName(), true);

ImmutableMap.Builder<String, Map<String, Object>> columnMetadata = ImmutableMap.builder();
columnMetadata.putAll(getColumnsMetadata(handle.getMetadataEntry()));
columnMetadata.put(newColumnMetadata.getName(), ImmutableMap.of());
Expand All @@ -1153,7 +1153,7 @@ public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle
columnsBuilder.build(),
partitionColumns,
columnComments.buildOrThrow(),
columnNullability.buildOrThrow(),
columnsNullability.buildOrThrow(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a separate commit ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's related: we allow adding NOT NULL for empty tables
(previously it was ignored)

i think it;s fine to keep as one commit

columnMetadata.buildOrThrow(),
handle.getMetadataEntry().getConfiguration(),
ADD_COLUMN_OPERATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,9 @@ public void testTableWithNonNullableColumns()
}

@Override
public void testAddNotNullColumnToNonEmptyTable()
protected void verifyAddNotNullColumnToNonEmptyTableFailurePermissible(Throwable e)
{
// TODO https://github.com/trinodb/trino/issues/13587 Disallow adding a new column when the table isn't empty
assertThatThrownBy(super::testAddNotNullColumnToNonEmptyTable)
.hasMessageContaining("expected [false] but found [true]");
assertThat(e).hasMessageMatching("Unable to add NOT NULL column '.*' for non-empty table: .*");
}

@Override
Expand Down