Skip to content

Commit

Permalink
The column name should be case sensitive when inject column stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jibing-Li committed Mar 7, 2025
1 parent ca850fa commit 89a85b2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"""
}

0 comments on commit 89a85b2

Please sign in to comment.