diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java index 199e8f8d3c07d1..3cb2f110181b0a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java @@ -17,6 +17,7 @@ package org.apache.doris.analysis; +import org.apache.doris.catalog.Column; import org.apache.doris.catalog.DatabaseIf; import org.apache.doris.catalog.Env; import org.apache.doris.catalog.OlapTable; @@ -26,7 +27,6 @@ import org.apache.doris.common.AnalysisException; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; -import org.apache.doris.common.FeNameFormat; import org.apache.doris.common.UserException; import org.apache.doris.common.util.PrintableMap; import org.apache.doris.datasource.CatalogIf; @@ -173,10 +173,9 @@ private void checkPartitionAndColumn() throws AnalysisException { } indexId = idxId; } - - if (table.getColumn(columnName) == null) { - ErrorReport.reportAnalysisException(ErrorCode.ERR_WRONG_COLUMN_NAME, - columnName, FeNameFormat.getColumnNameRegex()); + Column column = table.getColumn(columnName); + if (column == null || !column.getName().equals(columnName)) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_FIELD_ERROR, columnName, table.getName()); } if (optPartitionNames != null && table instanceof OlapTable) { diff --git a/regression-test/suites/statistics/test_alter_table_set_column_stats.groovy b/regression-test/suites/statistics/test_alter_table_set_column_stats.groovy new file mode 100644 index 00000000000000..2979eb033e777d --- /dev/null +++ b/regression-test/suites/statistics/test_alter_table_set_column_stats.groovy @@ -0,0 +1,55 @@ +// 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. + +suite("test_alter_table_set_column_stats") { + + sql """drop database if exists test_alter_table_set_column_stats""" + sql """create database test_alter_table_set_column_stats""" + sql """use test_alter_table_set_column_stats""" + sql """set global force_sample_analyze=false""" + sql """set global enable_auto_analyze=false""" + sql """drop table if exists et""" + sql """ + CREATE TABLE `et` ( + `QTY` DECIMAL(18, 2) NOT NULL + ) ENGINE=OLAP + UNIQUE KEY(`QTY`) + COMMENT 'st_entry_detail_et' + DISTRIBUTED BY HASH(`QTY`) BUCKETS 40 + PROPERTIES ("replication_allocation" = "tag.location.default: 1"); + """ + + sql """alter table et modify column QTY set stats ('row_count'='1690909875', 'ndv'='836', 'min_value'='-893077', 'max_value'='987118080', 'avg_size'='288004948', 'max_size'='288004948' );""" + def result = sql """show column stats et""" + assertEquals(1, result.size()) + assertEquals("QTY", result[0][0]) + assertEquals("et", result[0][1]) + assertEquals("1.690909875E9", result[0][2]) + assertEquals("836.0", result[0][3]) + assertEquals("0.0", result[0][4]) + assertEquals("0.0", result[0][5]) + assertEquals("0.0", result[0][6]) + assertEquals("-893077", result[0][7]) + assertEquals("987118080", result[0][8]) + + test { + sql """alter table et modify column qty set stats ('row_count'='1690909875', 'ndv'='836', 'min_value'='-893077', 'max_value'='987118080', 'avg_size'='288004948', 'max_size'='288004948' );""" + exception "Unknown column 'qty' in 'et'" + } + sql """drop database if exists test_alter_table_set_column_stats""" +} +