diff --git a/paimon-core/src/main/java/org/apache/paimon/table/system/BucketsTable.java b/paimon-core/src/main/java/org/apache/paimon/table/system/BucketsTable.java index 303238268a9e..ccc260ef0b79 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/system/BucketsTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/system/BucketsTable.java @@ -57,7 +57,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.TreeMap; +import java.util.stream.Collectors; import static org.apache.paimon.catalog.Catalog.SYSTEM_TABLE_SPLITTER; @@ -185,21 +185,23 @@ public RecordReader createReader(Split split) { fileStoreTable.schema().logicalPartitionType()); // sorted by partition and bucket - Map, BucketEntry> pairBucketsMap = - new TreeMap<>( - Comparator.comparing((Pair o) -> o.getLeft()) - .thenComparing(Pair::getRight)); - buckets.forEach( - entry -> - pairBucketsMap.put( - Pair.of( - Arrays.toString(converter.convert(entry.partition())), - entry.bucket()), - entry)); + List> bucketList = + buckets.stream() + .map( + entry -> + Pair.of( + Arrays.toString( + converter.convert(entry.partition())), + entry)) + .sorted( + Comparator.comparing( + (Pair p) -> p.getLeft()) + .thenComparing(p -> p.getRight().bucket())) + .collect(Collectors.toList()); List results = new ArrayList<>(buckets.size()); - for (Map.Entry, BucketEntry> pair : pairBucketsMap.entrySet()) { - results.add(toRow(pair.getKey().getLeft(), pair.getValue())); + for (Pair pair : bucketList) { + results.add(toRow(pair.getLeft(), pair.getRight())); } Iterator iterator = results.iterator();