public static int calAvgBucketNumOfRecentPartitions(OlapTable olapTable, int recentPartitionNum,
                                                        boolean enableAutoTabletDistribution) {
        // 1. If the partition is less than recentPartitionNum, use backendNum to speculate the bucketNum
        //    Or the Config.enable_auto_tablet_distribution is disabled
        int bucketNum = 0;
        if (olapTable.getPartitions().size() < recentPartitionNum || !enableAutoTabletDistribution) {
            bucketNum = CatalogUtils.calBucketNumAccordingToBackends();
            // If table is not partitioned, the bucketNum should be at least DEFAULT_UNPARTITIONED_TABLE_BUCKET_NUM
            if (!olapTable.getPartitionInfo().isPartitioned()) {
                bucketNum = bucketNum > FeConstants.DEFAULT_UNPARTITIONED_TABLE_BUCKET_NUM ?
                        bucketNum : FeConstants.DEFAULT_UNPARTITIONED_TABLE_BUCKET_NUM;
            }
            return bucketNum;
        }

        // 2. If the partition is not imported anydata, use backendNum to speculate the bucketNum
        List<Partition> partitions = (List<Partition>) olapTable.getRecentPartitions(recentPartitionNum);
        boolean dataImported = true;
        for (Partition partition : partitions) {
            if (partition.getVisibleVersion() == 1) {
                dataImported = false;
                break;
            }
        }

        bucketNum = CatalogUtils.calBucketNumAccordingToBackends();
        if (!dataImported) {
            return bucketNum;
        }

        // 3. Use the totalSize of recentPartitions to speculate the bucketNum
        long maxDataSize = 0;
        for (Partition partition : partitions) {
            maxDataSize = Math.max(maxDataSize, partition.getDataSize());
        }
        // A tablet will be regarded using the 1GB size
        // And also the number will not be larger than the calBucketNumAccordingToBackends()
        long speculateTabletNum = (maxDataSize + FeConstants.AUTO_DISTRIBUTION_UNIT - 1) / FeConstants.AUTO_DISTRIBUTION_UNIT;
        // speculateTabletNum may be not accurate, so we need to take the max value of bucketNum and speculateTabletNum
        bucketNum = (int) Math.max(bucketNum, speculateTabletNum);
        if (bucketNum == 0) {
            bucketNum = 1;
        }
        return bucketNum;
    }
@Test
    public void testCalAvgBucketNumOfRecentPartitions_CalculateByDataSize() {
        List<Partition> partitions = new ArrayList<>();
        partitions.add(partition);
        when(olapTable.getPartitions()).thenReturn(partitions);
        when(olapTable.getRecentPartitions(anyInt())).thenReturn(partitions);
        when(partition.getVisibleVersion()).thenReturn(2L);
        when(partition.getDataSize()).thenReturn(2L * FeConstants.AUTO_DISTRIBUTION_UNIT);

        int bucketNum = CatalogUtils.calAvgBucketNumOfRecentPartitions(olapTable, 1, true);

        assertEquals(2, bucketNum); // 2 tablets based on 2GB size
    }