This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 78d51ca3202 [fix](Nereids) tablet prune wrong when decimal value scale
is nagtive (#37889) (#38013)
78d51ca3202 is described below
commit 78d51ca320278ad11f4c5f31bcbb29a55670b98b
Author: morrySnow <[email protected]>
AuthorDate: Wed Jul 17 20:12:14 2024 +0800
[fix](Nereids) tablet prune wrong when decimal value scale is nagtive
(#37889) (#38013)
pick from master #37889
we use unscaled value of BigDecimal in tablet prune. So we need to
ensure BigDecimal's precision and scale is same with the literal
contains it.
---
.../rules/SimplifyDecimalV3Comparison.java | 8 ++++-
.../olap_scan_tablet_prune/test_decimal_type.out | 4 +++
.../noStatsRfPrune/query28.out | 2 +-
.../no_stats_shape/query28.out | 2 +-
.../rf_prune/query28.out | 2 +-
.../nereids_tpcds_shape_sf100_p0/shape/query28.out | 2 +-
.../test_decimal_type.groovy | 38 ++++++++++++++++++++++
7 files changed, 53 insertions(+), 5 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyDecimalV3Comparison.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyDecimalV3Comparison.java
index c3c3c17dd55..450e9cd6055 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyDecimalV3Comparison.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyDecimalV3Comparison.java
@@ -29,6 +29,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.List;
/**
@@ -72,10 +73,15 @@ public class SimplifyDecimalV3Comparison implements
ExpressionPatternRuleFactory
BigDecimal trailingZerosValue = right.getValue().stripTrailingZeros();
int scale =
org.apache.doris.analysis.DecimalLiteral.getBigDecimalScale(trailingZerosValue);
int precision =
org.apache.doris.analysis.DecimalLiteral.getBigDecimalPrecision(trailingZerosValue);
+ try {
+ trailingZerosValue = trailingZerosValue.setScale(scale,
RoundingMode.UNNECESSARY);
+ } catch (ArithmeticException e) {
+ return cp;
+ }
+
Expression castChild = left.child();
Preconditions.checkState(castChild.getDataType() instanceof
DecimalV3Type);
DecimalV3Type leftType = (DecimalV3Type) castChild.getDataType();
-
if (scale <= leftType.getScale() && precision - scale <=
leftType.getPrecision() - leftType.getScale()) {
// precision and scale of literal all smaller than left, we don't
need the cast
DecimalV3Literal newRight = new DecimalV3Literal(
diff --git
a/regression-test/data/nereids_rules_p0/olap_scan_tablet_prune/test_decimal_type.out
b/regression-test/data/nereids_rules_p0/olap_scan_tablet_prune/test_decimal_type.out
new file mode 100644
index 00000000000..1c2095fe8c3
--- /dev/null
+++
b/regression-test/data/nereids_rules_p0/olap_scan_tablet_prune/test_decimal_type.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !test_decimal_prune --
+20240750 550
+
diff --git
a/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query28.out
b/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query28.out
index 72124f34ee3..ae9c833b99f 100644
---
a/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query28.out
+++
b/regression-test/data/nereids_tpcds_shape_sf100_p0/noStatsRfPrune/query28.out
@@ -33,7 +33,7 @@ PhysicalResultSink
--------------------------PhysicalDistribute[DistributionSpecGather]
----------------------------hashAgg[LOCAL]
------------------------------PhysicalProject
---------------------------------filter(((((store_sales.ss_list_price >=
150.00) AND (store_sales.ss_list_price <= 1.6E+2)) OR
((store_sales.ss_coupon_amt >= 6600.00) AND (store_sales.ss_coupon_amt <=
7.6E+3))) OR ((store_sales.ss_wholesale_cost >= 9.00) AND
(store_sales.ss_wholesale_cost <= 29.00))) and (store_sales.ss_quantity <= 15)
and (store_sales.ss_quantity >= 11))
+--------------------------------filter(((((store_sales.ss_list_price >=
150.00) AND (store_sales.ss_list_price <= 160.00)) OR
((store_sales.ss_coupon_amt >= 6600.00) AND (store_sales.ss_coupon_amt <=
7600.00))) OR ((store_sales.ss_wholesale_cost >= 9.00) AND
(store_sales.ss_wholesale_cost <= 29.00))) and (store_sales.ss_quantity <= 15)
and (store_sales.ss_quantity >= 11))
----------------------------------PhysicalOlapScan[store_sales]
----------------PhysicalDistribute[DistributionSpecReplicated]
------------------PhysicalLimit[LOCAL]
diff --git
a/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query28.out
b/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query28.out
index 72124f34ee3..ae9c833b99f 100644
---
a/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query28.out
+++
b/regression-test/data/nereids_tpcds_shape_sf100_p0/no_stats_shape/query28.out
@@ -33,7 +33,7 @@ PhysicalResultSink
--------------------------PhysicalDistribute[DistributionSpecGather]
----------------------------hashAgg[LOCAL]
------------------------------PhysicalProject
---------------------------------filter(((((store_sales.ss_list_price >=
150.00) AND (store_sales.ss_list_price <= 1.6E+2)) OR
((store_sales.ss_coupon_amt >= 6600.00) AND (store_sales.ss_coupon_amt <=
7.6E+3))) OR ((store_sales.ss_wholesale_cost >= 9.00) AND
(store_sales.ss_wholesale_cost <= 29.00))) and (store_sales.ss_quantity <= 15)
and (store_sales.ss_quantity >= 11))
+--------------------------------filter(((((store_sales.ss_list_price >=
150.00) AND (store_sales.ss_list_price <= 160.00)) OR
((store_sales.ss_coupon_amt >= 6600.00) AND (store_sales.ss_coupon_amt <=
7600.00))) OR ((store_sales.ss_wholesale_cost >= 9.00) AND
(store_sales.ss_wholesale_cost <= 29.00))) and (store_sales.ss_quantity <= 15)
and (store_sales.ss_quantity >= 11))
----------------------------------PhysicalOlapScan[store_sales]
----------------PhysicalDistribute[DistributionSpecReplicated]
------------------PhysicalLimit[LOCAL]
diff --git
a/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query28.out
b/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query28.out
index 72124f34ee3..ae9c833b99f 100644
--- a/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query28.out
+++ b/regression-test/data/nereids_tpcds_shape_sf100_p0/rf_prune/query28.out
@@ -33,7 +33,7 @@ PhysicalResultSink
--------------------------PhysicalDistribute[DistributionSpecGather]
----------------------------hashAgg[LOCAL]
------------------------------PhysicalProject
---------------------------------filter(((((store_sales.ss_list_price >=
150.00) AND (store_sales.ss_list_price <= 1.6E+2)) OR
((store_sales.ss_coupon_amt >= 6600.00) AND (store_sales.ss_coupon_amt <=
7.6E+3))) OR ((store_sales.ss_wholesale_cost >= 9.00) AND
(store_sales.ss_wholesale_cost <= 29.00))) and (store_sales.ss_quantity <= 15)
and (store_sales.ss_quantity >= 11))
+--------------------------------filter(((((store_sales.ss_list_price >=
150.00) AND (store_sales.ss_list_price <= 160.00)) OR
((store_sales.ss_coupon_amt >= 6600.00) AND (store_sales.ss_coupon_amt <=
7600.00))) OR ((store_sales.ss_wholesale_cost >= 9.00) AND
(store_sales.ss_wholesale_cost <= 29.00))) and (store_sales.ss_quantity <= 15)
and (store_sales.ss_quantity >= 11))
----------------------------------PhysicalOlapScan[store_sales]
----------------PhysicalDistribute[DistributionSpecReplicated]
------------------PhysicalLimit[LOCAL]
diff --git
a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query28.out
b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query28.out
index 72124f34ee3..ae9c833b99f 100644
--- a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query28.out
+++ b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query28.out
@@ -33,7 +33,7 @@ PhysicalResultSink
--------------------------PhysicalDistribute[DistributionSpecGather]
----------------------------hashAgg[LOCAL]
------------------------------PhysicalProject
---------------------------------filter(((((store_sales.ss_list_price >=
150.00) AND (store_sales.ss_list_price <= 1.6E+2)) OR
((store_sales.ss_coupon_amt >= 6600.00) AND (store_sales.ss_coupon_amt <=
7.6E+3))) OR ((store_sales.ss_wholesale_cost >= 9.00) AND
(store_sales.ss_wholesale_cost <= 29.00))) and (store_sales.ss_quantity <= 15)
and (store_sales.ss_quantity >= 11))
+--------------------------------filter(((((store_sales.ss_list_price >=
150.00) AND (store_sales.ss_list_price <= 160.00)) OR
((store_sales.ss_coupon_amt >= 6600.00) AND (store_sales.ss_coupon_amt <=
7600.00))) OR ((store_sales.ss_wholesale_cost >= 9.00) AND
(store_sales.ss_wholesale_cost <= 29.00))) and (store_sales.ss_quantity <= 15)
and (store_sales.ss_quantity >= 11))
----------------------------------PhysicalOlapScan[store_sales]
----------------PhysicalDistribute[DistributionSpecReplicated]
------------------PhysicalLimit[LOCAL]
diff --git
a/regression-test/suites/nereids_rules_p0/olap_scan_tablet_prune/test_decimal_type.groovy
b/regression-test/suites/nereids_rules_p0/olap_scan_tablet_prune/test_decimal_type.groovy
new file mode 100644
index 00000000000..779e70b36c1
--- /dev/null
+++
b/regression-test/suites/nereids_rules_p0/olap_scan_tablet_prune/test_decimal_type.groovy
@@ -0,0 +1,38 @@
+// 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_decimal_type") {
+
+ sql """
+ drop table if exists test_decimal_type
+ """
+
+ sql """
+ create table test_decimal_type (c1 decimal(8, 0), c2 decimal(18, 0))
duplicate key(c1, c2) distributed by hash(c1, c2) buckets 10
properties("replication_num"="1");
+ """
+
+ sql """
+ insert into test_decimal_type values (20240710, 110), (20240720,220),
(20240120, 120), (20240730, 330), (20240740,440),(20240750,550);
+ """
+
+ sql """
+ sync
+ """
+
+ order_qt_test_decimal_prune """
+ select * from test_decimal_type where c1 = 20240750 and c2 = 550
+ """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]