[BugFix] forbidden statistics collect generate expr column (backport #61829) (#61870)

Signed-off-by: Seaven <seaven_7@qq.com>
Co-authored-by: Seaven <seaven_7@qq.com>
This commit is contained in:
mergify[bot] 2025-08-13 16:01:33 +08:00 committed by GitHub
parent 898d7a400e
commit 288b12572d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -438,9 +438,17 @@ public class StatisticUtils {
List<String> columns = new ArrayList<>();
for (Column column : table.getBaseSchema()) {
// disable stats collection for auto generated columns, see SelectAnalyzer#analyzeSelect
if (column.isGeneratedColumn() && column.getName().startsWith(FeConstants.GENERATED_PARTITION_COLUMN_PREFIX)) {
if (column.isGeneratedColumn() && column.getName()
.startsWith(FeConstants.GENERATED_PARTITION_COLUMN_PREFIX)) {
continue;
}
// generated column doesn't support cross DB use
if (column.isGeneratedColumn() && column.generatedColumnExprToString() != null) {
String expr = column.generatedColumnExprToString().toLowerCase();
if (expr.contains("dict_mapping") || expr.contains("dictionary_get")) {
continue;
}
}
if (!column.isAggregated()) {
columns.add(column.getName());
} else if (isPrimaryEngine && column.getAggregationType().equals(AggregateType.REPLACE)) {

View File

@ -14,14 +14,19 @@
package com.starrocks.sql.analyzer;
import com.starrocks.catalog.OlapTable;
import com.starrocks.common.Config;
import com.starrocks.qe.ConnectContext;
import com.starrocks.server.RunMode;
import com.starrocks.statistic.StatisticUtils;
import com.starrocks.utframe.StarRocksAssert;
import com.starrocks.utframe.UtFrameUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.List;
public class DictQueryFunctionTest {
private static final String TEST_DICT_DATABASE = "dict";
@ -160,6 +165,25 @@ public class DictQueryFunctionTest {
RunMode.detectRunMode();
}
@Test
public void testDictTable() throws Exception {
starRocksAssert.useDatabase(TEST_DICT_DATABASE);
starRocksAssert.withTable("CREATE TABLE `dd0` (\n" +
" `k1` int(11) NOT NULL,\n" +
" `k2` BIGINT(11) NULL AS dict_mapping('dict_table', `k1`, TRUE)\n" +
") ENGINE=OLAP\n" +
"DUPLICATE KEY(`k1`)\n" +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\"\n" +
");");
OlapTable table = (OlapTable) starRocksAssert.getTable(TEST_DICT_DATABASE, "dd0");
List<String> cols = StatisticUtils.getCollectibleColumns(table);
Assertions.assertEquals(1, cols.size());
starRocksAssert.dropTable("dd0");
}
private void testDictMappingFunction(String sql, String expectException) {
new ExceptionChecker(sql)
.withException(SemanticException.class)