morrySnow commented on code in PR #35517:
URL: https://github.com/apache/doris/pull/35517#discussion_r1617106899


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionStatistic.java:
##########
@@ -0,0 +1,165 @@
+// 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 org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.io.Hll;
+import org.apache.doris.statistics.util.Hll128;
+import org.apache.doris.statistics.util.StatisticsUtil;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.util.Base64;
+import java.util.List;
+
+public class PartitionStatistic {
+
+    private static final Logger LOG = 
LogManager.getLogger(PartitionStatistic.class);
+
+    public static PartitionStatistic UNKNOWN = new 
PartitionStatisticBuilder().setAvgSizeByte(1).setNdv(new Hll128())
+            
.setNumNulls(1).setCount(1).setMaxValue(Double.POSITIVE_INFINITY).setMinValue(Double.NEGATIVE_INFINITY)
+            .setIsUnknown(true).setUpdatedTime("")
+            .build();
+
+    public static PartitionStatistic ZERO = new 
PartitionStatisticBuilder().setAvgSizeByte(0).setNdv(new Hll128())
+            
.setNumNulls(0).setCount(0).setMaxValue(Double.NaN).setMinValue(Double.NaN)
+            .build();
+
+    public final double count;
+    public final Hll128 ndv;
+    public final double numNulls;
+    public final double dataSize;
+    public final double avgSizeByte;
+    public final double minValue;
+    public final double maxValue;
+    public final boolean isUnKnown;
+    public final LiteralExpr minExpr;
+    public final LiteralExpr maxExpr;
+    public final String updatedTime;
+
+    public PartitionStatistic(double count, Hll128 ndv, double avgSizeByte,
+                           double numNulls, double dataSize, double minValue, 
double maxValue,
+                           LiteralExpr minExpr, LiteralExpr maxExpr, boolean 
isUnKnown,
+                           String updatedTime) {
+        this.count = count;
+        this.ndv = ndv;
+        this.avgSizeByte = avgSizeByte;
+        this.numNulls = numNulls;
+        this.dataSize = dataSize;
+        this.minValue = minValue;
+        this.maxValue = maxValue;
+        this.minExpr = minExpr;
+        this.maxExpr = maxExpr;
+        this.isUnKnown = isUnKnown;
+        this.updatedTime = updatedTime;
+    }
+
+    public static PartitionStatistic fromResultRow(List<ResultRow> resultRows) 
{
+        if (resultRows.size() > 1) {
+            for (ResultRow resultRow : resultRows) {
+                LOG.warn("Partition stats has more than one row. [{}]", 
resultRow);
+            }
+        }
+        PartitionStatistic partitionStatistic = null;
+        try {
+            for (ResultRow resultRow : resultRows) {
+                partitionStatistic = fromResultRow(resultRow);

Review Comment:
   so we just get the last one? could u add some comment to explain why?



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionStatisticCacheLoader.java:
##########
@@ -0,0 +1,80 @@
+// 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 org.apache.doris.qe.InternalQueryExecutionException;
+import org.apache.doris.statistics.util.StatisticsUtil;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Optional;
+
+public class PartitionStatisticCacheLoader extends
+        BasicAsyncCacheLoader<PartitionStatisticCacheKey, 
Optional<PartitionStatistic>> {
+
+    private static final Logger LOG = 
LogManager.getLogger(PartitionStatisticCacheLoader.class);
+
+    @Override
+    protected Optional<PartitionStatistic> doLoad(PartitionStatisticCacheKey 
key) {
+        Optional<PartitionStatistic> partitionStatistic = Optional.empty();
+        try {
+            partitionStatistic = loadFromStatsTable(key);
+        } catch (Throwable t) {
+            LOG.warn("Failed to load stats for column [Catalog:{}, DB:{}, 
Table:{}, Part:{}, Column:{}],"
+                    + "Reason: {}", key.catalogId, key.dbId, key.tableId, 
key.partId, key.colName, t.getMessage());
+            if (LOG.isDebugEnabled()) {
+                LOG.debug(t);
+            }
+        }
+        if (partitionStatistic.isPresent()) {
+            // For non-empty table, return UNKNOWN if we can't collect ndv 
value.
+            // Because inaccurate ndv is very misleading.
+            PartitionStatistic stats = partitionStatistic.get();
+            if (stats.count > 0 && stats.ndv.estimateCardinality() == 0 && 
stats.count != stats.numNulls) {
+                partitionStatistic = Optional.of(PartitionStatistic.UNKNOWN);
+            }
+        }
+        return partitionStatistic;
+    }
+
+    private Optional<PartitionStatistic> 
loadFromStatsTable(PartitionStatisticCacheKey key) {
+        List<ResultRow> partitionResults;
+        try {
+            partitionResults = StatisticsRepository.loadPartitionStats(
+                key.catalogId, key.dbId, key.tableId, key.idxId, key.partId, 
key.colName);
+        } catch (InternalQueryExecutionException e) {
+            LOG.info("Failed to load stats for table {} column {}. Reason:{}",
+                    key.tableId, key.colName, e.getMessage());
+            return Optional.empty();
+        }
+        PartitionStatistic partitionStatistic;
+        try {
+            partitionStatistic = 
StatisticsUtil.deserializeToPartitionStatistics(partitionResults);
+        } catch (Exception e) {
+            LOG.warn("Exception to deserialize partition statistics", e);
+            return Optional.empty();
+        }
+        if (partitionStatistic == null) {
+            return Optional.empty();
+        } else {
+            return Optional.of(partitionStatistic);
+        }

Review Comment:
   ```suggestion
           return Optional.ofNullable(partitionStatistic);
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionStatistic.java:
##########
@@ -0,0 +1,165 @@
+// 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 org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.io.Hll;
+import org.apache.doris.statistics.util.Hll128;
+import org.apache.doris.statistics.util.StatisticsUtil;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.util.Base64;
+import java.util.List;
+
+public class PartitionStatistic {
+
+    private static final Logger LOG = 
LogManager.getLogger(PartitionStatistic.class);
+
+    public static PartitionStatistic UNKNOWN = new 
PartitionStatisticBuilder().setAvgSizeByte(1).setNdv(new Hll128())
+            
.setNumNulls(1).setCount(1).setMaxValue(Double.POSITIVE_INFINITY).setMinValue(Double.NEGATIVE_INFINITY)
+            .setIsUnknown(true).setUpdatedTime("")
+            .build();
+
+    public static PartitionStatistic ZERO = new 
PartitionStatisticBuilder().setAvgSizeByte(0).setNdv(new Hll128())
+            
.setNumNulls(0).setCount(0).setMaxValue(Double.NaN).setMinValue(Double.NaN)
+            .build();
+
+    public final double count;
+    public final Hll128 ndv;
+    public final double numNulls;
+    public final double dataSize;
+    public final double avgSizeByte;
+    public final double minValue;
+    public final double maxValue;
+    public final boolean isUnKnown;
+    public final LiteralExpr minExpr;
+    public final LiteralExpr maxExpr;
+    public final String updatedTime;
+
+    public PartitionStatistic(double count, Hll128 ndv, double avgSizeByte,
+                           double numNulls, double dataSize, double minValue, 
double maxValue,
+                           LiteralExpr minExpr, LiteralExpr maxExpr, boolean 
isUnKnown,
+                           String updatedTime) {
+        this.count = count;
+        this.ndv = ndv;
+        this.avgSizeByte = avgSizeByte;
+        this.numNulls = numNulls;
+        this.dataSize = dataSize;
+        this.minValue = minValue;
+        this.maxValue = maxValue;
+        this.minExpr = minExpr;
+        this.maxExpr = maxExpr;
+        this.isUnKnown = isUnKnown;
+        this.updatedTime = updatedTime;
+    }
+
+    public static PartitionStatistic fromResultRow(List<ResultRow> resultRows) 
{
+        if (resultRows.size() > 1) {
+            for (ResultRow resultRow : resultRows) {
+                LOG.warn("Partition stats has more than one row. [{}]", 
resultRow);
+            }
+        }
+        PartitionStatistic partitionStatistic = null;
+        try {
+            for (ResultRow resultRow : resultRows) {
+                partitionStatistic = fromResultRow(resultRow);
+            }
+        } catch (Throwable t) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Failed to deserialize column stats", t);
+            }
+            return PartitionStatistic.UNKNOWN;
+        }
+        if (partitionStatistic == null) {
+            return PartitionStatistic.UNKNOWN;
+        }
+        return partitionStatistic;
+    }
+
+    public static PartitionStatistic fromResultRow(ResultRow row) {
+        // row : [catalog_id, db_id, tbl_id, idx_id, 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);
+            Column col = StatisticsUtil.findColumn(catalogId, dbID, tblId, 
idxId, colName);
+            if (col == null) {
+                LOG.info("Failed to deserialize column statistics, ctlId: {} 
dbId: {}, "
+                        + "tblId: {} column: {} not exists", catalogId, dbID, 
tblId, colName);
+                return PartitionStatistic.UNKNOWN;
+            }
+
+            PartitionStatisticBuilder partitionStatisticBuilder = new 
PartitionStatisticBuilder();
+            double count = Double.parseDouble(row.get(5));
+            partitionStatisticBuilder.setCount(count);
+            String ndv = row.get(6);
+            Base64.Decoder decoder = Base64.getDecoder();
+            DataInputStream dis = new DataInputStream(new 
ByteArrayInputStream(decoder.decode(ndv)));
+            Hll hll = new Hll();
+            if (!hll.deserialize(dis)) {
+                LOG.warn("Failed to deserialize ndv. {}", ndv);

Review Comment:
   log ids for easy debug?



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionStatisticBuilder.java:
##########
@@ -0,0 +1,160 @@
+// 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 org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.statistics.util.Hll128;
+
+public class PartitionStatisticBuilder {
+    private double count;
+    private Hll128 ndv;
+    private double avgSizeByte;
+    private double numNulls;
+    private double dataSize;
+    private double minValue = Double.NEGATIVE_INFINITY;
+    private double maxValue = Double.POSITIVE_INFINITY;

Review Comment:
   why these two have default value?



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionStatistic.java:
##########
@@ -0,0 +1,165 @@
+// 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 org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.io.Hll;
+import org.apache.doris.statistics.util.Hll128;
+import org.apache.doris.statistics.util.StatisticsUtil;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.util.Base64;
+import java.util.List;
+
+public class PartitionStatistic {
+
+    private static final Logger LOG = 
LogManager.getLogger(PartitionStatistic.class);
+
+    public static PartitionStatistic UNKNOWN = new 
PartitionStatisticBuilder().setAvgSizeByte(1).setNdv(new Hll128())
+            
.setNumNulls(1).setCount(1).setMaxValue(Double.POSITIVE_INFINITY).setMinValue(Double.NEGATIVE_INFINITY)
+            .setIsUnknown(true).setUpdatedTime("")
+            .build();
+
+    public static PartitionStatistic ZERO = new 
PartitionStatisticBuilder().setAvgSizeByte(0).setNdv(new Hll128())
+            
.setNumNulls(0).setCount(0).setMaxValue(Double.NaN).setMinValue(Double.NaN)
+            .build();
+
+    public final double count;
+    public final Hll128 ndv;
+    public final double numNulls;
+    public final double dataSize;
+    public final double avgSizeByte;
+    public final double minValue;
+    public final double maxValue;
+    public final boolean isUnKnown;
+    public final LiteralExpr minExpr;
+    public final LiteralExpr maxExpr;
+    public final String updatedTime;
+
+    public PartitionStatistic(double count, Hll128 ndv, double avgSizeByte,
+                           double numNulls, double dataSize, double minValue, 
double maxValue,
+                           LiteralExpr minExpr, LiteralExpr maxExpr, boolean 
isUnKnown,
+                           String updatedTime) {
+        this.count = count;
+        this.ndv = ndv;
+        this.avgSizeByte = avgSizeByte;
+        this.numNulls = numNulls;
+        this.dataSize = dataSize;
+        this.minValue = minValue;
+        this.maxValue = maxValue;
+        this.minExpr = minExpr;
+        this.maxExpr = maxExpr;
+        this.isUnKnown = isUnKnown;
+        this.updatedTime = updatedTime;
+    }
+
+    public static PartitionStatistic fromResultRow(List<ResultRow> resultRows) 
{
+        if (resultRows.size() > 1) {
+            for (ResultRow resultRow : resultRows) {
+                LOG.warn("Partition stats has more than one row. [{}]", 
resultRow);
+            }
+        }
+        PartitionStatistic partitionStatistic = null;
+        try {
+            for (ResultRow resultRow : resultRows) {
+                partitionStatistic = fromResultRow(resultRow);
+            }
+        } catch (Throwable t) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Failed to deserialize column stats", t);
+            }
+            return PartitionStatistic.UNKNOWN;
+        }
+        if (partitionStatistic == null) {
+            return PartitionStatistic.UNKNOWN;
+        }
+        return partitionStatistic;
+    }
+
+    public static PartitionStatistic fromResultRow(ResultRow row) {
+        // row : [catalog_id, db_id, tbl_id, idx_id, 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);
+            Column col = StatisticsUtil.findColumn(catalogId, dbID, tblId, 
idxId, colName);
+            if (col == null) {
+                LOG.info("Failed to deserialize column statistics, ctlId: {} 
dbId: {}, "
+                        + "tblId: {} column: {} not exists", catalogId, dbID, 
tblId, colName);
+                return PartitionStatistic.UNKNOWN;
+            }
+
+            PartitionStatisticBuilder partitionStatisticBuilder = new 
PartitionStatisticBuilder();
+            double count = Double.parseDouble(row.get(5));
+            partitionStatisticBuilder.setCount(count);
+            String ndv = row.get(6);
+            Base64.Decoder decoder = Base64.getDecoder();
+            DataInputStream dis = new DataInputStream(new 
ByteArrayInputStream(decoder.decode(ndv)));
+            Hll hll = new Hll();
+            if (!hll.deserialize(dis)) {
+                LOG.warn("Failed to deserialize ndv. {}", ndv);
+                return null;
+            }
+            partitionStatisticBuilder.setNdv(Hll128.fromHll(hll));
+            String nullCount = row.getWithDefault(7, "0");
+            
partitionStatisticBuilder.setNumNulls(Double.parseDouble(nullCount));
+            partitionStatisticBuilder.setDataSize(Double
+                    .parseDouble(row.getWithDefault(10, "0")));
+            
partitionStatisticBuilder.setAvgSizeByte(partitionStatisticBuilder.getCount() 
== 0
+                    ? 0 : partitionStatisticBuilder.getDataSize()
+                    / partitionStatisticBuilder.getCount());
+            String min = row.get(8);
+            String max = row.get(9);
+            if (min != null && !min.equalsIgnoreCase("NULL")) {

Review Comment:
   ```suggestion
               if (!"NULL".equalsIgnoreCase(min)) {
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsRepository.java:
##########
@@ -67,6 +67,12 @@ public class StatisticsRepository {
             + FULL_QUALIFIED_COLUMN_STATISTICS_NAME
             + " 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
+            + " WHERE `catalog_id` = '${catalogId}' AND `db_id` = '${dbId}' 
AND `tbl_id` = ${tableId}"
+            + " AND `idx_id` = ${indexId} AND `part_id` = '${partId}' AND 
`col_id` = '${columnId}'";

Review Comment:
   quote all identifier for safe



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionStatistic.java:
##########
@@ -0,0 +1,165 @@
+// 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 org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.io.Hll;
+import org.apache.doris.statistics.util.Hll128;
+import org.apache.doris.statistics.util.StatisticsUtil;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.util.Base64;
+import java.util.List;
+
+public class PartitionStatistic {
+
+    private static final Logger LOG = 
LogManager.getLogger(PartitionStatistic.class);
+
+    public static PartitionStatistic UNKNOWN = new 
PartitionStatisticBuilder().setAvgSizeByte(1).setNdv(new Hll128())
+            
.setNumNulls(1).setCount(1).setMaxValue(Double.POSITIVE_INFINITY).setMinValue(Double.NEGATIVE_INFINITY)
+            .setIsUnknown(true).setUpdatedTime("")
+            .build();
+
+    public static PartitionStatistic ZERO = new 
PartitionStatisticBuilder().setAvgSizeByte(0).setNdv(new Hll128())
+            
.setNumNulls(0).setCount(0).setMaxValue(Double.NaN).setMinValue(Double.NaN)
+            .build();
+
+    public final double count;
+    public final Hll128 ndv;
+    public final double numNulls;
+    public final double dataSize;
+    public final double avgSizeByte;
+    public final double minValue;
+    public final double maxValue;
+    public final boolean isUnKnown;
+    public final LiteralExpr minExpr;
+    public final LiteralExpr maxExpr;
+    public final String updatedTime;
+
+    public PartitionStatistic(double count, Hll128 ndv, double avgSizeByte,
+                           double numNulls, double dataSize, double minValue, 
double maxValue,
+                           LiteralExpr minExpr, LiteralExpr maxExpr, boolean 
isUnKnown,
+                           String updatedTime) {
+        this.count = count;
+        this.ndv = ndv;
+        this.avgSizeByte = avgSizeByte;
+        this.numNulls = numNulls;
+        this.dataSize = dataSize;
+        this.minValue = minValue;
+        this.maxValue = maxValue;
+        this.minExpr = minExpr;
+        this.maxExpr = maxExpr;
+        this.isUnKnown = isUnKnown;
+        this.updatedTime = updatedTime;
+    }
+
+    public static PartitionStatistic fromResultRow(List<ResultRow> resultRows) 
{
+        if (resultRows.size() > 1) {
+            for (ResultRow resultRow : resultRows) {
+                LOG.warn("Partition stats has more than one row. [{}]", 
resultRow);

Review Comment:
   Why is each result row printed as a separate line in the log?



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowColumnStatsStmt.java:
##########
@@ -225,6 +228,32 @@ public ShowResultSet 
constructPartitionResultSet(List<ResultRow> resultRows, Tab
         return new ShowResultSet(getMetaData(), result);
     }
 
+    public ShowResultSet constructPartitionCachedStats(
+            Map<PartitionStatisticCacheKey, PartitionStatistic> resultMap, 
TableIf tableIf) {
+        List<List<String>> result = Lists.newArrayList();
+        for (Map.Entry<PartitionStatisticCacheKey, PartitionStatistic> entry : 
resultMap.entrySet()) {
+            PartitionStatisticCacheKey key = entry.getKey();
+            PartitionStatistic value = entry.getValue();
+            List<String> row = Lists.newArrayList();
+            row.add(key.colName); // column_name
+            row.add(key.partId); // partition_name
+            long indexId = key.idxId;
+            String indexName = indexId == -1 ? tableIf.getName() : 
((OlapTable) tableIf).getIndexNameById(indexId);
+            row.add(indexName); // index_name.
+            row.add(String.valueOf(value.count)); // count
+            row.add(String.valueOf(value.ndv.estimateCardinality())); // ndv
+            row.add(String.valueOf(value.numNulls)); // num_null
+            row.add(String.valueOf(value.minValue)); // min
+            row.add(String.valueOf(value.maxValue)); // max
+            row.add(String.valueOf(value.dataSize)); // data_size
+            row.add(value.updatedTime); // updated_time
+            row.add("N/A"); // update_rows
+            row.add("N/A"); // trigger. Manual or System

Review Comment:
   it is a TODO?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to