From 268196ed26a661ad51e466dba33c87570c24019f Mon Sep 17 00:00:00 2001 From: starocean999 Date: Mon, 18 Nov 2024 20:48:24 +0800 Subject: [PATCH] [fix](nereids)the column name should be case insensitive in tablet prune --- .../rules/rewrite/PruneOlapScanTablet.java | 4 +-- .../org/apache/doris/planner/ScanNode.java | 3 +- .../planner/HashDistributionPrunerTest.java | 24 +++++++------- .../doris/planner/OlapScanNodeTest.java | 5 +-- .../tablet_prune/test_tablet_prune.groovy | 32 +++++++++++++++++++ 5 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 regression-test/suites/nereids_rules_p0/tablet_prune/test_tablet_prune.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanTablet.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanTablet.java index 8cf4f91deecea1..4b86b7a3706f0e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanTablet.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanTablet.java @@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; -import com.google.common.collect.Maps; +import org.apache.commons.collections.map.CaseInsensitiveMap; import java.util.Collection; import java.util.HashSet; @@ -80,7 +80,7 @@ private Collection getSelectedTabletIds(Set expressions, return index.getTabletIdsInOrder(); } HashDistributionInfo hashInfo = (HashDistributionInfo) info; - Map filterMap = Maps.newHashMap(); + Map filterMap = new CaseInsensitiveMap(); expressions.stream().map(ExpressionUtils::checkAndMaybeCommute).filter(Optional::isPresent) .forEach(expr -> new ExpressionColumnFilterConverter(filterMap).convert(expr.get())); return new HashDistributionPruner(index.getTabletIdsInOrder(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java index 4a4d43d424b5ca..23c2c91be6e9e4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java @@ -65,6 +65,7 @@ import com.google.common.collect.RangeSet; import com.google.common.collect.Sets; import com.google.common.collect.TreeRangeSet; +import org.apache.commons.collections.map.CaseInsensitiveMap; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -84,7 +85,7 @@ public abstract class ScanNode extends PlanNode implements SplitGenerator { protected static final int NUM_SPLITTERS_ON_FLIGHT = Config.max_external_cache_loader_thread_pool_size; protected final TupleDescriptor desc; // for distribution prunner - protected Map columnFilters = Maps.newHashMap(); + protected Map columnFilters = new CaseInsensitiveMap(); // Use this if partition_prune_algorithm_version is 2. protected Map columnNameToRange = Maps.newHashMap(); protected String sortColumn = null; diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/HashDistributionPrunerTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/HashDistributionPrunerTest.java index 2da47314d6871a..e2896ee239091e 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/HashDistributionPrunerTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/HashDistributionPrunerTest.java @@ -26,8 +26,8 @@ import org.apache.doris.catalog.PrimitiveType; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import org.apache.commons.collections.map.CaseInsensitiveMap; import org.junit.Assert; import org.junit.Test; @@ -84,12 +84,12 @@ public void test() { inList4.add(new StringLiteral("2")); shopTypeFilter.setInPredicate(new InPredicate(new SlotRef(null, "shop_type"), inList4, false)); - Map filters = Maps.newHashMap(); - filters.put("dealDate", dealDatefilter); - filters.put("main_brand_id", mainBrandFilter); - filters.put("item_third_cate_id", itemThirdFilter); - filters.put("channel", channelFilter); - filters.put("shop_type", shopTypeFilter); + Map filters = new CaseInsensitiveMap(); + filters.put("DEALDATE", dealDatefilter); + filters.put("MAIN_BRAND_ID", mainBrandFilter); + filters.put("ITEM_THIRD_CATE_ID", itemThirdFilter); + filters.put("CHANNEL", channelFilter); + filters.put("SHOP_TYPE", shopTypeFilter); HashDistributionPruner pruner = new HashDistributionPruner(tabletIds, columns, filters, tabletIds.size(), true); @@ -97,16 +97,16 @@ public void test() { // 20 = 1 * 5 * 2 * 2 * 1 (element num of each filter) Assert.assertEquals(20, results.size()); - filters.get("shop_type").getInPredicate().addChild(new StringLiteral("4")); + filters.get("SHOP_TYPE").getInPredicate().addChild(new StringLiteral("4")); results = pruner.prune(); // 40 = 1 * 5 * 2 * 2 * 2 (element num of each filter) // 39 is because these is hash conflict Assert.assertEquals(39, results.size()); - filters.get("shop_type").getInPredicate().addChild(new StringLiteral("5")); - filters.get("shop_type").getInPredicate().addChild(new StringLiteral("6")); - filters.get("shop_type").getInPredicate().addChild(new StringLiteral("7")); - filters.get("shop_type").getInPredicate().addChild(new StringLiteral("8")); + filters.get("SHOP_TYPE").getInPredicate().addChild(new StringLiteral("5")); + filters.get("SHOP_TYPE").getInPredicate().addChild(new StringLiteral("6")); + filters.get("SHOP_TYPE").getInPredicate().addChild(new StringLiteral("7")); + filters.get("SHOP_TYPE").getInPredicate().addChild(new StringLiteral("8")); results = pruner.prune(); // 120 = 1 * 5 * 2 * 2 * 6 (element num of each filter) > 100 Assert.assertEquals(300, results.size()); diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/OlapScanNodeTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/OlapScanNodeTest.java index d8d785435585f8..417cf8b55d02fe 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/OlapScanNodeTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/OlapScanNodeTest.java @@ -31,6 +31,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import org.apache.commons.collections.map.CaseInsensitiveMap; import org.junit.Assert; import org.junit.Test; @@ -62,8 +63,8 @@ public void testHashDistributionOneUser() throws AnalysisException { PartitionColumnFilter columnFilter = new PartitionColumnFilter(); columnFilter.setInPredicate(inPredicate); - Map filterMap = Maps.newHashMap(); - filterMap.put("columnA", columnFilter); + Map filterMap = new CaseInsensitiveMap(); + filterMap.put("COLUMNA", columnFilter); DistributionPruner partitionPruner = new HashDistributionPruner( partitions, diff --git a/regression-test/suites/nereids_rules_p0/tablet_prune/test_tablet_prune.groovy b/regression-test/suites/nereids_rules_p0/tablet_prune/test_tablet_prune.groovy new file mode 100644 index 00000000000000..6b69d86bf1f141 --- /dev/null +++ b/regression-test/suites/nereids_rules_p0/tablet_prune/test_tablet_prune.groovy @@ -0,0 +1,32 @@ +// 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_tablet_prune") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + + sql "drop table if exists t_customers_wide_index" + sql """ + CREATE TABLE `t_customers_wide_index` ( `CUSTOMER_ID` int NULL, `ADDRESS` varchar(1500) NULL) ENGINE=OLAP UNIQUE KEY(`CUSTOMER_ID`) DISTRIBUTED BY HASH(`CUSTOMER_ID`) BUCKETS 32 PROPERTIES ( "replication_allocation" = "tag.location.default: 1", "file_cache_ttl_seconds" = "0", "is_being_synced" = "false", "storage_medium" = "hdd", "storage_format" = "V2", "inverted_index_storage_format" = "V2", "enable_unique_key_merge_on_write" = "true", "light_schema_change" = "true", "store_row_column" = "true", "row_store_page_size" = "16384", "disable_auto_compaction" = "false", "enable_single_replica_compaction" = "false", "group_commit_interval_ms" = "10000", "group_commit_data_bytes" = "134217728", "enable_mow_light_delete" = "false" ); """ + sql """ + insert into t_customers_wide_index values (1, "111"); + """ + explain { + sql("SELECT * from t_customers_wide_index WHERE customer_id = 1817422;") + contains "tablets=1/32" + } +} \ No newline at end of file