Skip to content

Commit

Permalink
Disallow write operations for Delta CDF and deletion vectors
Browse files Browse the repository at this point in the history
Also, check table attributes in OPTIMIZE procedure.
  • Loading branch information
ebyhr authored and wendigo committed Oct 3, 2024
1 parent 6f7937c commit 7119730
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,8 @@ public Optional<ConnectorTableExecuteHandle> getTableHandleForExecute(

private Optional<ConnectorTableExecuteHandle> getTableHandleForOptimize(DeltaLakeTableHandle tableHandle, Map<String, Object> executeProperties, RetryMode retryMode)
{
checkWriteSupported(tableHandle);

DataSize maxScannedFileSize = (DataSize) executeProperties.get("file_size_threshold");

List<DeltaLakeColumnHandle> columns = getColumns(tableHandle.getMetadataEntry(), tableHandle.getProtocolEntry()).stream()
Expand Down Expand Up @@ -2850,6 +2852,12 @@ private void checkWriteSupported(DeltaLakeTableHandle handle)
}
checkUnsupportedUniversalFormat(handle.getMetadataEntry());
checkUnsupportedWriterFeatures(handle.getProtocolEntry());

boolean changeDataFeedEnabled = changeDataFeedEnabled(handle.getMetadataEntry(), handle.getProtocolEntry()).orElse(false);
boolean deletionVectorEnabled = isDeletionVectorEnabled(handle.getMetadataEntry(), handle.getProtocolEntry());
if (changeDataFeedEnabled && deletionVectorEnabled) {
throw new TrinoException(NOT_SUPPORTED, "Writing to tables with both change data feed and deletion vectors enabled is not supported");
}
}

public static void checkUnsupportedUniversalFormat(MetadataEntry metadataEntry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,26 @@ public void testCreateTableWithChangeDataFeed()
}
}

@Test
public void testUnsupportedChangeDataFeedAndDeletionVector()
{
// TODO https://github.com/trinodb/trino/issues/23620 Fix incorrect CDF entry when deletion vector is enabled
try (TestTable table = new TestTable(
getQueryRunner()::execute,
"test_cdf_dv",
"(x int) WITH (change_data_feed_enabled = true, deletion_vectors_enabled = true)")) {
assertQueryFails("INSERT INTO " + table.getName() + " VALUES 1", "Writing to tables with both change data feed and deletion vectors enabled is not supported");
assertQueryFails("UPDATE " + table.getName() + " SET x = 1", "Writing to tables with both change data feed and deletion vectors enabled is not supported");
assertQueryFails("DELETE FROM " + table.getName(), "Writing to tables with both change data feed and deletion vectors enabled is not supported");
assertQueryFails("MERGE INTO " + table.getName() + " USING (VALUES 42) t(dummy) ON false WHEN NOT MATCHED THEN INSERT VALUES (1)", "Writing to tables with both change data feed and deletion vectors enabled is not supported");
assertQueryFails("TRUNCATE TABLE " + table.getName(), "Writing to tables with both change data feed and deletion vectors enabled is not supported");
assertQueryFails("ALTER TABLE " + table.getName() + " EXECUTE optimize", "Writing to tables with both change data feed and deletion vectors enabled is not supported");

// TODO https://github.com/trinodb/trino/issues/22809 Add support for vacuuming tables with deletion vectors
assertQueryFails("CALL system.vacuum(current_schema, '" + table.getName() + "', '7d')", "Cannot execute vacuum procedure with deletionVectors writer features");
}
}

@Test
public void testUnsupportedCreateTableWithChangeDataFeed()
{
Expand Down

0 comments on commit 7119730

Please sign in to comment.