From 6acfd82701687415fef52e2beb4447a828158609 Mon Sep 17 00:00:00 2001 From: Marius Grama Date: Fri, 9 Sep 2022 16:54:18 +0200 Subject: [PATCH] Avoid reloading the Iceberg table for optimize --- .../trino/plugin/iceberg/IcebergMetadata.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 5ebc47eb005e..70fec7ee7f55 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 @@ -889,7 +889,7 @@ public Optional 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: @@ -901,24 +901,23 @@ public Optional getTableHandleForExecute( throw new IllegalArgumentException("Unknown procedure: " + procedureId); } - private Optional getTableHandleForOptimize(ConnectorSession session, IcebergTableHandle tableHandle, Map executeProperties, RetryMode retryMode) + private Optional getTableHandleForOptimize(IcebergTableHandle tableHandle, Map 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 getTableHandleForDropExtendedStats(ConnectorSession session, IcebergTableHandle tableHandle)