Skip to content

Commit 97d2d82

Browse files
authored
[fix](Nereids) tablet prune wrong when decimal value scale is nagtive (#37889) (#38280)
pick from master #37889
1 parent 331d445 commit 97d2d82

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyDecimalV3Comparison.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.common.base.Preconditions;
2929

3030
import java.math.BigDecimal;
31+
import java.math.RoundingMode;
3132

3233
/**
3334
* if we have a column with decimalv3 type and set enable_decimal_conversion = false.
@@ -64,10 +65,15 @@ private Expression doProcess(ComparisonPredicate cp, Cast left, DecimalV3Literal
6465
BigDecimal trailingZerosValue = right.getValue().stripTrailingZeros();
6566
int scale = org.apache.doris.analysis.DecimalLiteral.getBigDecimalScale(trailingZerosValue);
6667
int precision = org.apache.doris.analysis.DecimalLiteral.getBigDecimalPrecision(trailingZerosValue);
68+
try {
69+
trailingZerosValue = trailingZerosValue.setScale(scale, RoundingMode.UNNECESSARY);
70+
} catch (ArithmeticException e) {
71+
return cp;
72+
}
73+
6774
Expression castChild = left.child();
6875
Preconditions.checkState(castChild.getDataType() instanceof DecimalV3Type);
6976
DecimalV3Type leftType = (DecimalV3Type) castChild.getDataType();
70-
7177
if (scale <= leftType.getScale() && precision - scale <= leftType.getPrecision() - leftType.getScale()) {
7278
// precision and scale of literal all smaller than left, we don't need the cast
7379
DecimalV3Literal newRight = new DecimalV3Literal(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !test_decimal_prune --
3+
20240750 550
4+

regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query28.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ PhysicalResultSink
4444
----------------------------PhysicalDistribute
4545
------------------------------hashAgg[LOCAL]
4646
--------------------------------PhysicalProject
47-
----------------------------------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))
47+
----------------------------------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))
4848
------------------------------------PhysicalOlapScan[store_sales]
4949
------------------PhysicalDistribute
5050
--------------------hashAgg[LOCAL]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
suite("test_decimal_type") {
18+
19+
sql """
20+
drop table if exists test_decimal_type
21+
"""
22+
23+
sql """
24+
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");
25+
"""
26+
27+
sql """
28+
insert into test_decimal_type values (20240710, 110), (20240720,220), (20240120, 120), (20240730, 330), (20240740,440),(20240750,550);
29+
"""
30+
31+
sql """
32+
sync
33+
"""
34+
35+
order_qt_test_decimal_prune """
36+
select * from test_decimal_type where c1 = 20240750 and c2 = 550
37+
"""
38+
}

0 commit comments

Comments
 (0)