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 a600ae6
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 16 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
Expand Up @@ -127,7 +127,7 @@ suite("materialized_view_grouping_sets") {
sql """analyze table orders with sync;"""
sql """analyze table partsupp with sync;"""

sql """alter table orders modify column o_comment set stats ('row_count'='10');"""
sql """alter table orders modify column O_COMMENT set stats ('row_count'='10');"""
sql """alter table lineitem modify column l_comment set stats ('row_count'='7');"""

// query has group sets, and mv doesn't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ suite("outer_join_dphyp") {
sql """analyze table partsupp with sync;"""

sql """alter table lineitem modify column l_comment set stats ('row_count'='5');"""
sql """alter table orders modify column o_comment set stats ('row_count'='8');"""
sql """alter table orders modify column O_COMMENT set stats ('row_count'='8');"""
sql """alter table partsupp modify column ps_comment set stats ('row_count'='2');"""

// without filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ suite("outer_join") {

sql """alter table lineitem modify column l_comment set stats ('row_count'='5');"""
sql """alter table lineitem_same_col modify column l_comment set stats ('row_count'='5');"""
sql """alter table orders modify column o_comment set stats ('row_count'='8');"""
sql """alter table orders_same_col modify column o_comment set stats ('row_count'='18');"""
sql """alter table orders modify column O_COMMENT set stats ('row_count'='8');"""
sql """alter table orders_same_col modify column O_COMMENT set stats ('row_count'='18');"""
sql """alter table partsupp modify column ps_comment set stats ('row_count'='2');"""
sql """alter table lineitem_null modify column l_comment set stats ('row_count'='5');"""
sql """alter table orders_null modify column o_comment set stats ('row_count'='5');"""
sql """alter table orders_null modify column O_COMMENT set stats ('row_count'='5');"""


// without filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ suite("sync_async_same_name") {
(5, 2, 'o', 1.2, '2023-12-12', 'c','d',2, 'mi');
"""

sql """alter table orders modify column o_comment set stats ('row_count'='8');"""
sql """alter table orders modify column O_COMMENT set stats ('row_count'='8');"""

sql """analyze table orders with sync;"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ suite("single_table_without_aggregate") {
"""

sql "analyze table orders with sync;"
sql """alter table orders modify column o_comment set stats ('row_count'='2');"""
sql """alter table orders modify column O_COMMENT set stats ('row_count'='2');"""
sql """set enable_stats=false;"""

def check_rewrite = { mv_sql, query_sql, mv_name ->
Expand Down Expand Up @@ -324,4 +324,4 @@ suite("single_table_without_aggregate") {
check_rewrite(mv4_1, query7_3, "mv7_3")
order_qt_query7_3 "${query7_3}"
sql """DROP MATERIALIZED VIEW IF EXISTS mv7_3 ON orders"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ suite("null_unsafe_equals") {
(5, 2, 'o', 1.2, '2023-12-12', 'c','d', null, 'mi');
"""

sql """alter table orders modify column o_comment set stats ('row_count'='8');"""
sql """alter table orders modify column O_COMMENT set stats ('row_count'='8');"""

def mv1_0 =
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ suite("with_select_table_auth","p0,auth") {
sql """analyze table lineitem with sync"""
sql """analyze table orders with sync"""

sql """alter table orders modify column o_comment set stats ('row_count'='18');"""
sql """alter table orders modify column O_COMMENT set stats ('row_count'='18');"""
sql """alter table lineitem modify column l_comment set stats ('row_count'='5');"""

sql """grant select_priv on ${db}.orders to ${user_name}"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ suite("query_with_sql_limit") {
sql """analyze table lineitem with sync"""
sql """analyze table orders with sync"""

sql """alter table orders modify column o_comment set stats ('row_count'='18');"""
sql """alter table orders modify column O_COMMENT set stats ('row_count'='18');"""
sql """alter table lineitem modify column l_comment set stats ('row_count'='5');"""
sql """alter table partsupp modify column ps_comment set stats ('row_count'='3');"""

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 a600ae6

Please sign in to comment.