Skip to content

Commit

Permalink
Avoid reloading the Iceberg table for optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
findinpath authored and findepi committed Sep 19, 2022
1 parent d562faf commit 6acfd82
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ public Optional<ConnectorTableExecuteHandle> getTableHandleForExecute(

switch (procedureId) {
case OPTIMIZE:
return getTableHandleForOptimize(session, tableHandle, executeProperties, retryMode);
return getTableHandleForOptimize(tableHandle, executeProperties, retryMode);
case DROP_EXTENDED_STATS:
return getTableHandleForDropExtendedStats(session, tableHandle);
case EXPIRE_SNAPSHOTS:
Expand All @@ -901,24 +901,23 @@ public Optional<ConnectorTableExecuteHandle> getTableHandleForExecute(
throw new IllegalArgumentException("Unknown procedure: " + procedureId);
}

private Optional<ConnectorTableExecuteHandle> getTableHandleForOptimize(ConnectorSession session, IcebergTableHandle tableHandle, Map<String, Object> executeProperties, RetryMode retryMode)
private Optional<ConnectorTableExecuteHandle> getTableHandleForOptimize(IcebergTableHandle tableHandle, Map<String, Object> executeProperties, RetryMode retryMode)
{
DataSize maxScannedFileSize = (DataSize) executeProperties.get("file_size_threshold");
Table icebergTable = catalog.loadTable(session, tableHandle.getSchemaTableName());

return Optional.of(new IcebergTableExecuteHandle(
tableHandle.getSchemaTableName(),
OPTIMIZE,
new IcebergOptimizeHandle(
tableHandle.getSnapshotId(),
SchemaParser.toJson(icebergTable.schema()),
PartitionSpecParser.toJson(icebergTable.spec()),
getColumns(icebergTable.schema(), typeManager),
getFileFormat(icebergTable),
icebergTable.properties(),
tableHandle.getTableSchemaJson(),
tableHandle.getPartitionSpecJson().orElseThrow(() -> new VerifyException("Partition spec missing in the table handle")),
getColumns(SchemaParser.fromJson(tableHandle.getTableSchemaJson()), typeManager),
getFileFormat(tableHandle.getStorageProperties()),
tableHandle.getStorageProperties(),
maxScannedFileSize,
retryMode != NO_RETRIES),
icebergTable.location()));
tableHandle.getTableLocation()));
}

private Optional<ConnectorTableExecuteHandle> getTableHandleForDropExtendedStats(ConnectorSession session, IcebergTableHandle tableHandle)
Expand Down

0 comments on commit 6acfd82

Please sign in to comment.