This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 97d2d82f639 [fix](Nereids) tablet prune wrong when decimal value scale
is nagtive (#37889) (#38280)
97d2d82f639 is described below
commit 97d2d82f6394d2dafd3340b3941338a7c113290a
Author: morrySnow <[email protected]>
AuthorDate: Wed Jul 24 11:51:46 2024 +0800
[fix](Nereids) tablet prune wrong when decimal value scale is nagtive
(#37889) (#38280)
pick from master #37889
---
.../rules/SimplifyDecimalV3Comparison.java | 8 ++++-
.../olap_scan_tablet_prune/test_decimal_type.out | 4 +++
.../nereids_tpcds_shape_sf100_p0/shape/query28.out | 2 +-
.../test_decimal_type.groovy | 38 ++++++++++++++++++++++
4 files changed, 50 insertions(+), 2 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 fc1ee0cb91f..b821d7a4d19 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
@@ -28,6 +28,7 @@ import org.apache.doris.nereids.types.DecimalV3Type;
import com.google.common.base.Preconditions;
import java.math.BigDecimal;
+import java.math.RoundingMode;
/**
* if we have a column with decimalv3 type and set enable_decimal_conversion =
false.
@@ -64,10 +65,15 @@ public class SimplifyDecimalV3Comparison extends
AbstractExpressionRewriteRule {
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/shape/query28.out
b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query28.out
index a0c26768491..064f8595d2f 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
@@ -44,7 +44,7 @@ PhysicalResultSink
----------------------------PhysicalDistribute
------------------------------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)))(store_sales.ss_quantity >=
11)(store_sales.ss_quantity <= 15))
+----------------------------------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)))(store_sales.ss_quantity >=
11)(store_sales.ss_quantity <= 15))
------------------------------------PhysicalOlapScan[store_sales]
------------------PhysicalDistribute
--------------------hashAgg[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]