diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonMetadataCache.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonMetadataCache.java index 109394fabded6aa..c803ce3a61c7555 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonMetadataCache.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonMetadataCache.java @@ -33,7 +33,6 @@ import org.apache.paimon.data.InternalRow; import org.apache.paimon.table.Table; import org.apache.paimon.table.system.PartitionsTable; -import org.apache.paimon.table.system.SnapshotsTable; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -94,18 +93,14 @@ private List loadPartitions(PaimonSnapshotCacheKey key) } private PaimonSnapshot loadLatestSnapshot(PaimonSnapshotCacheKey key) throws IOException { - Table table = ((PaimonExternalCatalog) key.getCatalog()).getPaimonTable(key.getDbName(), - key.getTableName() + Catalog.SYSTEM_TABLE_SPLITTER + SnapshotsTable.SNAPSHOTS); + Table table = ((PaimonExternalCatalog) key.getCatalog()).getPaimonTable(key.getDbName(), key.getTableName()); // snapshotId and schemaId - List rows = PaimonUtil.read(table, new int[] {0, 1}, null); long latestSnapshotId = 0L; long latestSchemaId = 0L; - for (InternalRow row : rows) { - long snapshotId = row.getLong(0); - if (snapshotId > latestSnapshotId) { - latestSnapshotId = snapshotId; - latestSchemaId = row.getLong(1); - } + OptionalLong optionalSnapshotId = table.latestSnapshotId(); + if (optionalSnapshotId.isPresent()) { + latestSnapshotId = optionalSnapshotId.getAsLong(); + latestSchemaId = table.snapshot(latestSnapshotId).schemaId(); } return new PaimonSnapshot(latestSnapshotId, latestSchemaId); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonUtil.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonUtil.java index bbb1eaf50965204..7043673cc0d052c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/PaimonUtil.java @@ -69,7 +69,9 @@ public static List read( for (Pair, String> pair : dynamicOptions) { options.put(pair.getKey().key(), pair.getValue()); } - table = table.copy(options); + if (!options.isEmpty()) { + table = table.copy(options); + } ReadBuilder readBuilder = table.newReadBuilder(); if (projection != null) { readBuilder.withProjection(projection);