This is an automated email from the ASF dual-hosted git repository.

lijibing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new ea6e6d6dc90 [feature](statistics)Refresh partition stats cache while 
analyzing. (#36390)
ea6e6d6dc90 is described below

commit ea6e6d6dc90c6c0cd34bc3d56a3af7b7f5eb7df4
Author: Jibing-Li <64681310+jibing...@users.noreply.github.com>
AuthorDate: Mon Jun 17 22:24:23 2024 +0800

    [feature](statistics)Refresh partition stats cache while analyzing. (#36390)
    
    While doing partition level analyzing, we need to update the partition
    stats cache for all FEs, so that the cache are updated after analyzing
    finished. This pr is to support this.
---
 .../apache/doris/service/FrontendServiceImpl.java  | 11 +++++
 .../apache/doris/statistics/AnalysisManager.java   | 51 +++++++++++++++++++++
 .../apache/doris/statistics/BaseAnalysisTask.java  |  9 +++-
 .../doris/statistics/PartitionColumnStatistic.java | 19 ++++----
 .../PartitionColumnStatisticCacheLoader.java       |  3 +-
 .../apache/doris/statistics/StatisticsCache.java   | 31 +++++++++++--
 .../doris/statistics/StatisticsRepository.java     |  6 +--
 .../statistics/UpdatePartitionStatsTarget.java     | 53 ++++++++++++++++++++++
 gensrc/thrift/FrontendService.thrift               |  5 ++
 .../suites/statistics/test_partition_stats.groovy  | 47 +++++++++++++++++++
 10 files changed, 218 insertions(+), 17 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java 
b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
index 76a191dfbbb..30fc34a009d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
@@ -107,6 +107,7 @@ import org.apache.doris.statistics.ColumnStatistic;
 import org.apache.doris.statistics.InvalidateStatsTarget;
 import org.apache.doris.statistics.StatisticsCacheKey;
 import org.apache.doris.statistics.TableStatsMeta;
+import org.apache.doris.statistics.UpdatePartitionStatsTarget;
 import org.apache.doris.statistics.query.QueryStats;
 import org.apache.doris.system.Backend;
 import org.apache.doris.system.Frontend;
@@ -240,6 +241,7 @@ import org.apache.doris.thrift.TTabletLocation;
 import org.apache.doris.thrift.TTxnParams;
 import org.apache.doris.thrift.TUniqueId;
 import org.apache.doris.thrift.TUpdateExportTaskStatusRequest;
+import org.apache.doris.thrift.TUpdateFollowerPartitionStatsCacheRequest;
 import org.apache.doris.thrift.TUpdateFollowerStatsCacheRequest;
 import org.apache.doris.thrift.TWaitingTxnStatusRequest;
 import org.apache.doris.thrift.TWaitingTxnStatusResult;
@@ -988,6 +990,15 @@ public class FrontendServiceImpl implements 
FrontendService.Iface {
         }
     }
 
+    @Override
+    public TStatus 
updatePartitionStatsCache(TUpdateFollowerPartitionStatsCacheRequest request) {
+        UpdatePartitionStatsTarget target = 
GsonUtils.GSON.fromJson(request.key, UpdatePartitionStatsTarget.class);
+        AnalysisManager analysisManager = 
Env.getCurrentEnv().getAnalysisManager();
+        analysisManager.updateLocalPartitionStatsCache(target.catalogId, 
target.dbId, target.tableId,
+                target.indexId, target.partitions, target.columnName);
+        return new TStatus(TStatusCode.OK);
+    }
+
     @Override
     public TMasterResult finishTask(TFinishTaskRequest request) throws 
TException {
         return masterImpl.finishTask(request);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java
index 7ae4474c411..d2deade518d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java
@@ -73,6 +73,7 @@ import org.apache.doris.system.Frontend;
 import org.apache.doris.system.SystemInfoService;
 import org.apache.doris.thrift.TInvalidateFollowerStatsCacheRequest;
 import org.apache.doris.thrift.TQueryColumn;
+import org.apache.doris.thrift.TUpdateFollowerPartitionStatsCacheRequest;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
@@ -767,6 +768,56 @@ public class AnalysisManager implements Writable {
         }
     }
 
+    public void updatePartitionStatsCache(long catalogId, long dbId, long 
tableId, long indexId,
+                                        Set<String> partNames, String colName) 
{
+        updateLocalPartitionStatsCache(catalogId, dbId, tableId, indexId, 
partNames, colName);
+        updateRemotePartitionStats(catalogId, dbId, tableId, indexId, 
partNames, colName);
+    }
+
+    public void updateLocalPartitionStatsCache(long catalogId, long dbId, long 
tableId, long indexId,
+                                               Set<String> partNames, String 
colName) {
+        if (partNames == null || partNames.isEmpty()) {
+            return;
+        }
+        Iterator<String> iterator = partNames.iterator();
+        StringBuilder partNamePredicate = new StringBuilder();
+        while (iterator.hasNext()) {
+            partNamePredicate.append("'");
+            partNamePredicate.append(iterator.next());
+            partNamePredicate.append("'");
+            partNamePredicate.append(",");
+        }
+        if (partNamePredicate.length() > 0) {
+            partNamePredicate.delete(partNamePredicate.length() - 1, 
partNamePredicate.length());
+        }
+        List<ResultRow> resultRows = 
StatisticsRepository.loadPartitionColumnStats(
+                catalogId, dbId, tableId, indexId, 
partNamePredicate.toString(), colName);
+        // row : [catalog_id, db_id, tbl_id, idx_id, part_name, col_id,
+        //        count, ndv, null_count, min, max, data_size, update_time]
+        StatisticsCache cache = Env.getCurrentEnv().getStatisticsCache();
+        for (ResultRow row : resultRows) {
+            cache.updatePartitionColStatsCache(catalogId, dbId, tableId, 
indexId, row.get(4), colName,
+                    PartitionColumnStatistic.fromResultRow(row));
+        }
+    }
+
+    public void updateRemotePartitionStats(long catalogId, long dbId, long 
tableId, long indexId,
+                                           Set<String> partNames, String 
colName) {
+        UpdatePartitionStatsTarget target = new UpdatePartitionStatsTarget(
+                catalogId, dbId, tableId, indexId, colName, partNames);
+        TUpdateFollowerPartitionStatsCacheRequest request = new 
TUpdateFollowerPartitionStatsCacheRequest();
+        request.key = GsonUtils.GSON.toJson(target);
+        StatisticsCache statisticsCache = 
Env.getCurrentEnv().getStatisticsCache();
+        SystemInfoService.HostInfo selfNode = 
Env.getCurrentEnv().getSelfNode();
+        for (Frontend frontend : Env.getCurrentEnv().getFrontends(null)) {
+            // Skip master
+            if (selfNode.getHost().equals(frontend.getHost())) {
+                continue;
+            }
+            statisticsCache.updatePartitionStats(frontend, request);
+        }
+    }
+
     public void handleKillAnalyzeStmt(KillAnalysisJobStmt killAnalysisJobStmt) 
throws DdlException {
         Map<Long, BaseAnalysisTask> analysisTaskMap = 
analysisJobIdToTaskMap.remove(killAnalysisJobStmt.jobId);
         if (analysisTaskMap == null) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java
index 0f076013b03..5091ce53a20 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java
@@ -42,6 +42,7 @@ import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import org.apache.commons.text.StringSubstitutor;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -364,6 +365,7 @@ public abstract class BaseAnalysisTask {
         boolean isAllPartitions = info.partitionNames.isEmpty();
         Set<String> partitionNames = isAllPartitions ? tbl.getPartitionNames() 
: info.partitionNames;
         List<String> sqls = Lists.newArrayList();
+        Set<String> partNames = Sets.newHashSet();
         int count = 0;
         AnalysisManager analysisManager = 
Env.getServingEnv().getAnalysisManager();
         TableStatsMeta tableStatsStatus = 
analysisManager.findTableStatsStatus(tbl.getId());
@@ -415,10 +417,14 @@ public abstract class BaseAnalysisTask {
             cache.invalidatePartitionColumnStatsCache(
                     info.catalogId, info.dbId, info.tblId, info.indexId, part, 
col.getName());
             count++;
+            partNames.add(part);
             if (count == PARTITION_BATCH_SIZE) {
                 String sql = "INSERT INTO " + 
StatisticConstants.FULL_QUALIFIED_PARTITION_STATS_TBL_NAME
                         + Joiner.on(" UNION ALL ").join(sqls);
                 runInsert(sql);
+                analysisManager.updatePartitionStatsCache(info.catalogId, 
info.dbId, info.tblId, info.indexId,
+                        partNames, info.colName);
+                partNames.clear();
                 sqls.clear();
                 count = 0;
             }
@@ -427,6 +433,8 @@ public abstract class BaseAnalysisTask {
             String sql = "INSERT INTO " + 
StatisticConstants.FULL_QUALIFIED_PARTITION_STATS_TBL_NAME
                     + Joiner.on(" UNION ALL ").join(sqls);
             runInsert(sql);
+            analysisManager.updatePartitionStatsCache(info.catalogId, 
info.dbId, info.tblId, info.indexId,
+                    partNames, info.colName);
         }
         if (hasHughPartition) {
             tableSample = new TableSample(false, 
StatisticsUtil.getHugeTableSampleRows());
@@ -509,5 +517,4 @@ public abstract class BaseAnalysisTask {
             }
         }
     }
-
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionColumnStatistic.java
 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionColumnStatistic.java
index 3a440a9102a..24f2946cbc4 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionColumnStatistic.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionColumnStatistic.java
@@ -101,13 +101,14 @@ public class PartitionColumnStatistic {
     }
 
     public static PartitionColumnStatistic fromResultRow(ResultRow row) {
-        // row : [catalog_id, db_id, tbl_id, idx_id, col_id, count, ndv, 
null_count, min, max, data_size, update_time]
+        // row : [catalog_id, db_id, tbl_id, idx_id, part_name, col_id,
+        //        count, ndv, null_count, min, max, data_size, update_time]
         try {
             long catalogId = Long.parseLong(row.get(0));
             long dbID = Long.parseLong(row.get(1));
             long tblId = Long.parseLong(row.get(2));
             long idxId = Long.parseLong(row.get(3));
-            String colName = row.get(4);
+            String colName = row.get(5);
             Column col = StatisticsUtil.findColumn(catalogId, dbID, tblId, 
idxId, colName);
             if (col == null) {
                 LOG.info("Failed to deserialize column statistics, ctlId: {} 
dbId: {}, "
@@ -116,9 +117,9 @@ public class PartitionColumnStatistic {
             }
 
             PartitionColumnStatisticBuilder partitionStatisticBuilder = new 
PartitionColumnStatisticBuilder();
-            double count = Double.parseDouble(row.get(5));
+            double count = Double.parseDouble(row.get(6));
             partitionStatisticBuilder.setCount(count);
-            String ndv = row.get(6);
+            String ndv = row.get(7);
             Base64.Decoder decoder = Base64.getDecoder();
             DataInputStream dis = new DataInputStream(new 
ByteArrayInputStream(decoder.decode(ndv)));
             Hll hll = new Hll();
@@ -127,15 +128,15 @@ public class PartitionColumnStatistic {
                 return PartitionColumnStatistic.UNKNOWN;
             }
             partitionStatisticBuilder.setNdv(Hll128.fromHll(hll));
-            String nullCount = row.getWithDefault(7, "0");
+            String nullCount = row.getWithDefault(8, "0");
             
partitionStatisticBuilder.setNumNulls(Double.parseDouble(nullCount));
             partitionStatisticBuilder.setDataSize(Double
-                    .parseDouble(row.getWithDefault(10, "0")));
+                    .parseDouble(row.getWithDefault(11, "0")));
             
partitionStatisticBuilder.setAvgSizeByte(partitionStatisticBuilder.getCount() 
== 0
                     ? 0 : partitionStatisticBuilder.getDataSize()
                     / partitionStatisticBuilder.getCount());
-            String min = row.get(8);
-            String max = row.get(9);
+            String min = row.get(9);
+            String max = row.get(10);
             if (!"NULL".equalsIgnoreCase(min)) {
                 try {
                     
partitionStatisticBuilder.setMinValue(StatisticsUtil.convertToDouble(col.getType(),
 min));
@@ -158,7 +159,7 @@ public class PartitionColumnStatistic {
             } else {
                 
partitionStatisticBuilder.setMaxValue(Double.POSITIVE_INFINITY);
             }
-            partitionStatisticBuilder.setUpdatedTime(row.get(11));
+            partitionStatisticBuilder.setUpdatedTime(row.get(12));
             return partitionStatisticBuilder.build();
         } catch (Exception e) {
             LOG.warn("Failed to deserialize column statistics. Row [{}]", row, 
e);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionColumnStatisticCacheLoader.java
 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionColumnStatisticCacheLoader.java
index 478c90e2f11..ac807a0d5f7 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionColumnStatisticCacheLoader.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionColumnStatisticCacheLoader.java
@@ -57,8 +57,9 @@ public class PartitionColumnStatisticCacheLoader extends
     private Optional<PartitionColumnStatistic> 
loadFromPartitionStatsTable(PartitionColumnStatisticCacheKey key) {
         List<ResultRow> partitionResults;
         try {
+            String partName = "'" + key.partId + "'";
             partitionResults = StatisticsRepository.loadPartitionColumnStats(
-                key.catalogId, key.dbId, key.tableId, key.idxId, key.partId, 
key.colName);
+                key.catalogId, key.dbId, key.tableId, key.idxId, partName, 
key.colName);
         } catch (InternalQueryExecutionException e) {
             LOG.info("Failed to load stats for table {} column {}. Reason:{}",
                     key.tableId, key.colName, e.getMessage());
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java
index 9d5c15eff15..d333ecdb96d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCache.java
@@ -30,6 +30,7 @@ import org.apache.doris.system.SystemInfoService;
 import org.apache.doris.thrift.FrontendService;
 import org.apache.doris.thrift.TInvalidateFollowerStatsCacheRequest;
 import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.thrift.TUpdateFollowerPartitionStatsCacheRequest;
 import org.apache.doris.thrift.TUpdateFollowerStatsCacheRequest;
 
 import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
@@ -147,18 +148,24 @@ public class StatisticsCache {
     }
 
     public void invalidatePartitionColumnStatsCache(long ctlId, long dbId, 
long tblId, long idxId,
-                                                    String partId, String 
colName) {
-        if (partId == null) {
+                                                    String partName, String 
colName) {
+        if (partName == null) {
             return;
         }
         partitionColumnStatisticCache.synchronous().invalidate(
-            new PartitionColumnStatisticCacheKey(ctlId, dbId, tblId, idxId, 
partId, colName));
+            new PartitionColumnStatisticCacheKey(ctlId, dbId, tblId, idxId, 
partName, colName));
     }
 
     public void invalidateAllPartitionStatsCache() {
         partitionColumnStatisticCache.synchronous().invalidateAll();
     }
 
+    public void updatePartitionColStatsCache(long ctlId, long dbId, long 
tblId, long idxId,
+                                             String partName, String colName, 
PartitionColumnStatistic statistic) {
+        partitionColumnStatisticCache.synchronous().put(
+            new PartitionColumnStatisticCacheKey(ctlId, dbId, tblId, idxId, 
partName, colName), Optional.of(statistic));
+    }
+
     public void updateColStatsCache(long ctlId, long dbId, long tblId, long 
idxId, String colName,
             ColumnStatistic statistic) {
         columnStatisticsCache.synchronous()
@@ -294,4 +301,22 @@ public class StatisticsCache {
         f.obtrudeValue(Optional.of(c));
         columnStatisticsCache.put(k, f);
     }
+
+    @VisibleForTesting
+    public boolean updatePartitionStats(Frontend frontend, 
TUpdateFollowerPartitionStatsCacheRequest request) {
+        TNetworkAddress address = new TNetworkAddress(frontend.getHost(), 
frontend.getRpcPort());
+        FrontendService.Client client = null;
+        try {
+            client = ClientPool.frontendPool.borrowObject(address);
+            client.updatePartitionStatsCache(request);
+        } catch (Throwable t) {
+            LOG.warn("Failed to update partition stats cache of follower: {}", 
address, t);
+            return false;
+        } finally {
+            if (client != null) {
+                ClientPool.frontendPool.returnObject(address, client);
+            }
+        }
+        return true;
+    }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsRepository.java
 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsRepository.java
index f84f0181d44..bbcc9de3a28 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsRepository.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsRepository.java
@@ -66,10 +66,10 @@ public class StatisticsRepository {
             + " WHERE `id` = '${id}' AND `catalog_id` = '${catalogId}' AND 
`db_id` = '${dbId}'";
 
     private static final String FETCH_PARTITION_STATISTIC_TEMPLATE = "SELECT 
`catalog_id`, `db_id`, `tbl_id`, `idx_id`,"
-            + "`col_id`, `count`, hll_to_base64(`ndv`) as ndv, `null_count`, 
`min`, `max`, `data_size_in_bytes`, "
-            + "`update_time` FROM " + FULL_QUALIFIED_PARTITION_STATISTICS_NAME
+            + " `part_name`, `col_id`, `count`, hll_to_base64(`ndv`) as ndv, 
`null_count`, `min`, `max`, "
+            + "`data_size_in_bytes`, `update_time` FROM " + 
FULL_QUALIFIED_PARTITION_STATISTICS_NAME
             + " WHERE `catalog_id` = '${catalogId}' AND `db_id` = '${dbId}' 
AND `tbl_id` = ${tableId}"
-            + " AND `idx_id` = '${indexId}' AND `part_name` = '${partName}' 
AND `col_id` = '${columnId}'";
+            + " AND `idx_id` = '${indexId}' AND `part_name` IN (${partName}) 
AND `col_id` = '${columnId}'";
 
     private static final String FETCH_PARTITIONS_STATISTIC_TEMPLATE = "SELECT 
col_id, part_name, idx_id, count, "
             + "hll_cardinality(ndv) as ndv, null_count, min, max, 
data_size_in_bytes, update_time FROM "
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/UpdatePartitionStatsTarget.java
 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/UpdatePartitionStatsTarget.java
new file mode 100644
index 00000000000..65ed066bc7a
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/UpdatePartitionStatsTarget.java
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.statistics;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.Set;
+
+public class UpdatePartitionStatsTarget {
+
+    @SerializedName("catalogId")
+    public final long catalogId;
+
+    @SerializedName("dbId")
+    public final long dbId;
+
+    @SerializedName("tableId")
+    public final long tableId;
+
+    @SerializedName("indexId")
+    public final long indexId;
+
+    @SerializedName("column")
+    public final String columnName;
+
+    @SerializedName("partitions")
+    public final Set<String> partitions;
+
+    public UpdatePartitionStatsTarget(long catalogId, long dbId, long tableId,
+                                      long indexId, String columnName, 
Set<String> partitions) {
+        this.catalogId = catalogId;
+        this.dbId = dbId;
+        this.tableId = tableId;
+        this.indexId = indexId;
+        this.columnName = columnName;
+        this.partitions = partitions;
+    }
+}
diff --git a/gensrc/thrift/FrontendService.thrift 
b/gensrc/thrift/FrontendService.thrift
index 7c563a97272..ed0f333b958 100644
--- a/gensrc/thrift/FrontendService.thrift
+++ b/gensrc/thrift/FrontendService.thrift
@@ -1292,6 +1292,10 @@ struct TInvalidateFollowerStatsCacheRequest {
     1: optional string key;
 }
 
+struct TUpdateFollowerPartitionStatsCacheRequest {
+    1: optional string key;
+}
+
 struct TAutoIncrementRangeRequest {
     1: optional i64 db_id;
     2: optional i64 table_id;
@@ -1600,4 +1604,5 @@ service FrontendService {
     Status.TStatus syncQueryColumns(1: TSyncQueryColumns request)
 
     TFetchSplitBatchResult fetchSplitBatch(1: TFetchSplitBatchRequest request)
+    Status.TStatus updatePartitionStatsCache(1: 
TUpdateFollowerPartitionStatsCacheRequest request)
 }
diff --git a/regression-test/suites/statistics/test_partition_stats.groovy 
b/regression-test/suites/statistics/test_partition_stats.groovy
index fdd5682504c..49c6ec96ef6 100644
--- a/regression-test/suites/statistics/test_partition_stats.groovy
+++ b/regression-test/suites/statistics/test_partition_stats.groovy
@@ -366,6 +366,53 @@ suite("test_partition_stats") {
     result = sql """show column stats part4 partition(p1)"""
     assertEquals(9, result.size())
 
+    // Test update partition cache while analyzing
+    sql """CREATE TABLE `part5` (
+        `id` INT NULL,
+        `colint` INT NULL,
+        `coltinyint` tinyint NULL,
+        `colsmallint` smallINT NULL,
+        `colbigint` bigINT NULL,
+        `collargeint` largeINT NULL,
+        `colfloat` float NULL,
+        `coldouble` double NULL,
+        `coldecimal` decimal(27, 9) NULL
+    ) ENGINE=OLAP
+    DUPLICATE KEY(`id`)
+    COMMENT 'OLAP'
+    PARTITION BY RANGE(`id`)
+    (
+        PARTITION p1 VALUES [("-2147483648"), ("10000")),
+        PARTITION p2 VALUES [("10000"), ("20000")),
+        PARTITION p3 VALUES [("20000"), ("30000"))
+    )
+    DISTRIBUTED BY HASH(`id`) BUCKETS 3
+    PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1"
+    )"""
+    sql """Insert into part5 values (1, 1, 1, 1, 1, 1, 1.1, 1.1, 1.1), (2, 2, 
2, 2, 2, 2, 2.2, 2.2, 2.2), (3, 3, 3, 3, 3, 3, 3.3, 3.3, 3.3),(4, 4, 4, 4, 4, 
4, 4.4, 4.4, 4.4),(5, 5, 5, 5, 5, 5, 5.5, 5.5, 5.5),(6, 6, 6, 6, 6, 6, 6.6, 
6.6, 6.6),(1, 1, 1, 1, 1, 1, 1.1, 1.1, 1.1), (2, 2, 2, 2, 2, 2, 2.2, 2.2, 2.2), 
(3, 3, 3, 3, 3, 3, 3.3, 3.3, 3.3),(4, 4, 4, 4, 4, 4, 4.4, 4.4, 4.4),(5, 5, 5, 
5, 5, 5, 5.5, 5.5, 5.5),(6, 6, 6, 6, 6, 6, 6.6, 6.6, 6.6),(10001, 10001, 10001, 
10001, 10001, 10001, 1 [...]
+    sql """analyze table part5 with sync"""
+    result = sql """show column cached stats part5 partition(*)"""
+    assertEquals(27, result.size())
+    result = sql """show column cached stats part5(id) partition(*)"""
+    assertEquals(3, result.size())
+    result = sql """show column cached stats part5(id) partition(p1)"""
+    assertEquals(1, result.size())
+    assertEquals("id", result[0][0])
+    assertEquals("p1", result[0][1])
+    assertEquals("part5", result[0][2])
+    assertEquals("12.0", result[0][3])
+    assertEquals("6", result[0][4])
+    assertEquals("0.0", result[0][5])
+    assertEquals("1.0", result[0][6])
+    assertEquals("6.0", result[0][7])
+    assertEquals("48.0", result[0][8])
+    sql """drop stats part5 partition(p1)"""
+    result = sql """show column cached stats part5(id) partition(p1)"""
+    assertEquals(0, result.size())
+    result = sql """show column cached stats part5(id) partition(*)"""
+    assertEquals(2, result.size())
+
     sql """drop database test_partition_stats"""
 }
 


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

Reply via email to