From 8da4e89004abac97f055991f27cb78156608ce02 Mon Sep 17 00:00:00 2001 From: Seaven Date: Wed, 13 Nov 2024 17:02:01 +0800 Subject: [PATCH] update name Signed-off-by: Seaven --- .../statistic/StatisticExecutor.java | 2 +- .../statistic/hyper/FullQueryJob.java | 4 +-- ...isticSQLs.java => HyperStatisticSQLs.java} | 31 ++++++------------- .../statistic/hyper/MetaQueryJob.java | 8 ++--- .../statistic/hyper/SampleQueryJob.java | 4 +-- 5 files changed, 19 insertions(+), 30 deletions(-) rename fe/fe-core/src/main/java/com/starrocks/statistic/hyper/{StatisticSQLs.java => HyperStatisticSQLs.java} (84%) diff --git a/fe/fe-core/src/main/java/com/starrocks/statistic/StatisticExecutor.java b/fe/fe-core/src/main/java/com/starrocks/statistic/StatisticExecutor.java index 5d8657b8aed64..af3e7b1a63d9e 100644 --- a/fe/fe-core/src/main/java/com/starrocks/statistic/StatisticExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/statistic/StatisticExecutor.java @@ -141,7 +141,7 @@ private static Table lookupTable(Long dbId, Long tableId) { .collect(Collectors.toList()); List columnStats = Lists.newArrayList(); - if (CollectionUtils.isNotEmpty(columnWithFullStats)) { + if (CollectionUtils.isNotEmpty(columnWithFullStats) || Config.statistic_use_meta_statistics) { List columnNamesForStats = columnWithFullStats.stream().map(ColumnStatsMeta::getColumnName) .collect(Collectors.toList()); List columnTypesForStats = diff --git a/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/FullQueryJob.java b/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/FullQueryJob.java index 5af307a0d1dab..7d8b391212800 100644 --- a/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/FullQueryJob.java +++ b/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/FullQueryJob.java @@ -44,13 +44,13 @@ protected List buildQuerySQL() { } for (ColumnStats columnStat : columnStats) { - VelocityContext context = StatisticSQLs.buildBaseContext(db, table, partition, columnStat); + VelocityContext context = HyperStatisticSQLs.buildBaseContext(db, table, partition, columnStat); context.put("dataSize", columnStat.getFullDateSize()); context.put("countNullFunction", columnStat.getFullNullCount()); context.put("hllFunction", columnStat.getNDV()); context.put("maxFunction", columnStat.getMax()); context.put("minFunction", columnStat.getMin()); - String sql = StatisticSQLs.build(context, StatisticSQLs.BATCH_FULL_STATISTIC_TEMPLATE); + String sql = HyperStatisticSQLs.build(context, HyperStatisticSQLs.BATCH_FULL_STATISTIC_TEMPLATE); metaSQL.add(sql); } } diff --git a/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/StatisticSQLs.java b/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/HyperStatisticSQLs.java similarity index 84% rename from fe/fe-core/src/main/java/com/starrocks/statistic/hyper/StatisticSQLs.java rename to fe/fe-core/src/main/java/com/starrocks/statistic/hyper/HyperStatisticSQLs.java index 0de622b595f30..702feeac95fd4 100644 --- a/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/StatisticSQLs.java +++ b/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/HyperStatisticSQLs.java @@ -32,7 +32,7 @@ import java.util.Objects; import java.util.stream.Collectors; -public class StatisticSQLs { +public class HyperStatisticSQLs { private static final VelocityEngine DEFAULT_VELOCITY_ENGINE; static { @@ -54,8 +54,8 @@ public class StatisticSQLs { //| max | varchar(1048576) | NO | false | | | //| min | varchar(1048576) | NO | false | | | //| update_time | datetime | NO | false | | | - public static final String TABLE_NAME = "column_statistics"; - public static final String BATCH_FULL_STATISTIC_TEMPLATE = "SELECT cast($version as INT)" + + static final String TABLE_NAME = "column_statistics"; + static final String BATCH_FULL_STATISTIC_TEMPLATE = "SELECT cast($version as INT)" + ", cast($partitionId as BIGINT)" + // BIGINT ", '$columnNameStr'" + // VARCHAR ", cast(COUNT(1) as BIGINT)" + // BIGINT @@ -66,7 +66,7 @@ public class StatisticSQLs { ", $minFunction " + // VARCHAR " FROM `$dbName`.`$tableName` partition `$partitionName`"; - public static final String BATCH_META_STATISTIC_TEMPLATE = "SELECT cast($version as INT)" + + static final String BATCH_META_STATISTIC_TEMPLATE = "SELECT cast($version as INT)" + ", cast($partitionId as BIGINT)" + // BIGINT, partition_id ", '$columnNameStr'" + // VARCHAR, column_name ", cast(COUNT(*) as BIGINT)" + // BIGINT, row_count @@ -77,18 +77,7 @@ public class StatisticSQLs { ", $minFunction " + // VARCHAR, min " FROM `$dbName`.`$tableName` partitions(`$partitionName`) [_META_]"; - public static final String BATCH_DATA_STATISTIC_TEMPLATE = "SELECT cast($version as INT)" + - ", cast($partitionId as BIGINT)" + // BIGINT, partition_id - ", '$columnNameStr'" + // VARCHAR, column_name - ", cast(0 as BIGINT)" + // BIGINT, row_count - ", cast($dataSize as BIGINT)" + // BIGINT, data_size - ", $hllFunction" + // VARBINARY, ndv - ", cast($countNullFunction as BIGINT)" + // BIGINT, null_count - ", ''" + // VARCHAR, max - ", '' " + // VARCHAR, min - " FROM `$dbName`.`$tableName` partitions(`$partitionName`)"; - - public static final String BATCH_DATA_STATISTIC_SELECT_TEMPLATE = "SELECT cast($version as INT)" + + static final String BATCH_DATA_STATISTIC_SELECT_TEMPLATE = "SELECT cast($version as INT)" + ", cast($partitionId as BIGINT)" + // BIGINT, partition_id ", '$columnNameStr'" + // VARCHAR, column_name ", cast(0 as BIGINT)" + // BIGINT, row_count @@ -99,7 +88,7 @@ public class StatisticSQLs { ", '' " + // VARCHAR, min " FROM base_cte_table "; - public static final String BATCH_SAMPLE_STATISTIC_SELECT_TEMPLATE = "SELECT cast($version as INT)" + + static final String BATCH_SAMPLE_STATISTIC_SELECT_TEMPLATE = "SELECT cast($version as INT)" + ", cast($partitionId as BIGINT)" + // BIGINT ", '$columnNameStr'" + // VARCHAR ", cast($rowCount as BIGINT)" + // BIGINT @@ -110,13 +99,13 @@ public class StatisticSQLs { ", $minFunction " + // VARCHAR " FROM base_cte_table "; - public static String build(VelocityContext context, String template) { + static String build(VelocityContext context, String template) { StringWriter sw = new StringWriter(); DEFAULT_VELOCITY_ENGINE.evaluate(context, sw, "", template); return sw.toString(); } - public static VelocityContext buildBaseContext(Database db, Table table, Partition p, ColumnStats stats) { + static VelocityContext buildBaseContext(Database db, Table table, Partition p, ColumnStats stats) { VelocityContext context = new VelocityContext(); String columnNameStr = stats.getColumnNameStr(); String quoteColumnName = stats.getQuotedColumnName(); @@ -130,7 +119,7 @@ public static VelocityContext buildBaseContext(Database db, Table table, Partiti return context; } - public static String buildSampleSQL(Database db, Table table, Partition p, List stats, + static String buildSampleSQL(Database db, Table table, Partition p, List stats, PartitionSampler sampler, String template) { String tableName = "`" + db.getOriginName() + "`.`" + table.getName() + "`"; @@ -162,7 +151,7 @@ public static String buildSampleSQL(Database db, Table table, Partition p, List< context.put("countNullFunction", stat.getSampleNullCount(info)); context.put("maxFunction", stat.getMax()); context.put("minFunction", stat.getMin()); - groupSQLs.add(StatisticSQLs.build(context, template)); + groupSQLs.add(HyperStatisticSQLs.build(context, template)); } sqlBuilder.append(String.join(" UNION ALL ", groupSQLs)); return sqlBuilder.toString(); diff --git a/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/MetaQueryJob.java b/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/MetaQueryJob.java index a05f8c0d1c7af..cd516b6137bd6 100644 --- a/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/MetaQueryJob.java +++ b/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/MetaQueryJob.java @@ -85,10 +85,10 @@ private List buildBatchMetaQuerySQL(List queryColumns) { } for (ColumnStats columnStat : queryColumns) { - VelocityContext context = StatisticSQLs.buildBaseContext(db, table, partition, columnStat); + VelocityContext context = HyperStatisticSQLs.buildBaseContext(db, table, partition, columnStat); context.put("maxFunction", columnStat.getMax()); context.put("minFunction", columnStat.getMin()); - String sql = StatisticSQLs.build(context, StatisticSQLs.BATCH_META_STATISTIC_TEMPLATE); + String sql = HyperStatisticSQLs.build(context, HyperStatisticSQLs.BATCH_META_STATISTIC_TEMPLATE); metaSQL.add(sql); } } @@ -140,8 +140,8 @@ private List buildBatchNDVQuerySQL(List queryColumns) { continue; } for (List part : partColumns) { - String sql = StatisticSQLs.buildSampleSQL(db, table, partition, part, sampler, - StatisticSQLs.BATCH_DATA_STATISTIC_SELECT_TEMPLATE); + String sql = HyperStatisticSQLs.buildSampleSQL(db, table, partition, part, sampler, + HyperStatisticSQLs.BATCH_DATA_STATISTIC_SELECT_TEMPLATE); metaSQL.add(sql); } } diff --git a/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/SampleQueryJob.java b/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/SampleQueryJob.java index 5d7a9bc921a99..b3323361750cc 100644 --- a/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/SampleQueryJob.java +++ b/fe/fe-core/src/main/java/com/starrocks/statistic/hyper/SampleQueryJob.java @@ -48,8 +48,8 @@ protected List buildQuerySQL() { continue; } for (List stats : partColumns) { - String sql = StatisticSQLs.buildSampleSQL(db, table, partition, stats, sampler, - StatisticSQLs.BATCH_SAMPLE_STATISTIC_SELECT_TEMPLATE); + String sql = HyperStatisticSQLs.buildSampleSQL(db, table, partition, stats, sampler, + HyperStatisticSQLs.BATCH_SAMPLE_STATISTIC_SELECT_TEMPLATE); sampleSQLs.add(sql); } }