eldenmoon commented on code in PR #37217:
URL: https://github.com/apache/doris/pull/37217#discussion_r1663993413


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java:
##########
@@ -2761,6 +2762,50 @@ public List<Tablet> getAllTablets() throws 
AnalysisException {
         return tablets;
     }
 
+    // Get sample tablets for remote desc schema
+    // 1. Estimate tablets for a partition, 1 at least
+    // 2. Pick the partition sorted with id in desc order, greater id with the 
newest partition
+    // 3. Truncate to sampleSize
+    public List<Tablet> getSampleTablets(int sampleSize) throws 
AnalysisException {
+        List<Tablet> sampleTablets = new ArrayList<>();
+        Collection<Partition> partitions = getPartitions();
+        if (partitions.isEmpty()) {
+            throw new AnalysisException("No partitions available.");
+        }
+        // 1. Estimate tablets for a partition, 1 at least
+        int estimatePartitionTablets = Math.max(sampleSize / 
partitions.size(), 1);
+
+        // 2. Sort the partitions by id in descending order (greater id means 
the newest partition)
+        List<Partition> sortedPartitions = partitions.stream().sorted(new 
Comparator<Partition>() {
+            @Override
+            public int compare(Partition p1, Partition p2) {
+                // compare with desc order
+                return Long.compare(p2.getId(), p1.getId());
+            }
+        }).collect(Collectors.toList());
+
+        // 3. Collect tablets from partitions
+        for (Partition partition : sortedPartitions) {
+            List<Tablet> targetTablets = new 
ArrayList<>(partition.getBaseIndex().getTablets());
+            Collections.shuffle(targetTablets);
+

Review Comment:
   nice catch.done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to