Skip to content

Commit

Permalink
Fix alter column stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Jibing-Li committed Nov 16, 2023
1 parent fd6a2cb commit 2d72713
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.apache.doris.analysis.AlterColumnStatsStmt;
import org.apache.doris.analysis.TableName;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.Partition;
import org.apache.doris.common.AnalysisException;
Expand All @@ -35,6 +34,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -227,7 +228,6 @@ public static void alterColumnStatistics(AlterColumnStatsStmt alterColumnStatsSt
String dataSize = alterColumnStatsStmt.getValue(StatsType.DATA_SIZE);
ColumnStatisticBuilder builder = new ColumnStatisticBuilder();
String colName = alterColumnStatsStmt.getColumnName();
Column column = objects.table.getColumn(colName);
if (rowCount != null) {
builder.setCount(Double.parseDouble(rowCount));
}
Expand All @@ -239,14 +239,6 @@ public static void alterColumnStatistics(AlterColumnStatsStmt alterColumnStatsSt
if (nullCount != null) {
builder.setNumNulls(Double.parseDouble(nullCount));
}
if (min != null) {
builder.setMinExpr(StatisticsUtil.readableValue(column.getType(), min));
builder.setMinValue(StatisticsUtil.convertToDouble(column.getType(), min));
}
if (max != null) {
builder.setMaxExpr(StatisticsUtil.readableValue(column.getType(), max));
builder.setMaxValue(StatisticsUtil.convertToDouble(column.getType(), max));
}
if (dataSize != null) {
double size = Double.parseDouble(dataSize);
double rows = Double.parseDouble(rowCount);
Expand All @@ -269,8 +261,10 @@ public static void alterColumnStatistics(AlterColumnStatsStmt alterColumnStatsSt
params.put("count", String.valueOf(columnStatistic.count));
params.put("ndv", String.valueOf(columnStatistic.ndv));
params.put("nullCount", String.valueOf(columnStatistic.numNulls));
params.put("min", min == null ? "NULL" : min);
params.put("max", max == null ? "NULL" : max);
params.put("min", min == null ? "NULL" :
Base64.getEncoder().encodeToString(min.getBytes(StandardCharsets.UTF_8)));
params.put("max", max == null ? "NULL" :
Base64.getEncoder().encodeToString(max.getBytes(StandardCharsets.UTF_8)));
params.put("dataSize", String.valueOf(columnStatistic.dataSize));

if (partitionIds.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,45 @@ suite("test_hive_statistic", "p2,external,hive,external_remote,external_remote_h
assertEquals(result.size(), 1)
assertEquals(result[0][6], "N/A")
assertEquals(result[0][7], "N/A")

sql """use tpch1_parquet;"""
sql """drop stats region"""
sql """alter table region modify column r_comment set stats ('row_count'='5.0', 'ndv'='5.0', 'num_nulls'='0.0', 'data_size'='330.0', 'min_value'='ges. thinly even pinto beans ca', 'max_value'='uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl');"""
sql """alter table region modify column r_name set stats ('row_count'='5.0', 'ndv'='5.0', 'num_nulls'='0.0', 'data_size'='34.0', 'min_value'='AFRICA', 'max_value'='MIDDLE EAST');"""
sql """alter table region modify column r_regionkey set stats ('row_count'='5.0', 'ndv'='5.0', 'num_nulls'='0.0', 'data_size'='20.0', 'min_value'='0', 'max_value'='4');"""
result = sql """show column stats region(r_regionkey)"""
assertEquals(result.size(), 1)
assertEquals(result[0][0], "r_regionkey")
assertEquals(result[0][1], "5.0")
assertEquals(result[0][2], "5.0")
assertEquals(result[0][3], "0.0")
assertEquals(result[0][4], "20.0")
assertEquals(result[0][5], "4.0")
assertEquals(result[0][6], "0")
assertEquals(result[0][7], "4")

result = sql """show column stats region(r_comment)"""
assertEquals(result.size(), 1)
assertEquals(result[0][0], "r_comment")
assertEquals(result[0][1], "5.0")
assertEquals(result[0][2], "5.0")
assertEquals(result[0][3], "0.0")
assertEquals(result[0][4], "330.0")
assertEquals(result[0][5], "66.0")
assertEquals(result[0][6], "\'ges. thinly even pinto beans ca\'")
assertEquals(result[0][7], "\'uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl\'")

result = sql """show column stats region(r_name)"""
assertEquals(result.size(), 1)
assertEquals(result[0][0], "r_name")
assertEquals(result[0][1], "5.0")
assertEquals(result[0][2], "5.0")
assertEquals(result[0][3], "0.0")
assertEquals(result[0][4], "34.0")
assertEquals(result[0][5], "6.8")
assertEquals(result[0][6], "\'AFRICA\'")
assertEquals(result[0][7], "\'MIDDLE EAST\'")

sql """drop catalog ${catalog_name}"""
}
}
Expand Down

0 comments on commit 2d72713

Please sign in to comment.