You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by st...@apache.org on 2024/03/19 06:37:09 UTC
(doris) branch branch-2.0 updated: [fix](planner)decimalv3 literal's precision and scale is not correctly set (#32432)
This is an automated email from the ASF dual-hosted git repository.
starocean999 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 dbe86ca0b1c [fix](planner)decimalv3 literal's precision and scale is not correctly set (#32432)
dbe86ca0b1c is described below
commit dbe86ca0b1c09be92431fbe074c3ce7df43a5165
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Tue Mar 19 14:37:02 2024 +0800
[fix](planner)decimalv3 literal's precision and scale is not correctly set (#32432)
---
.../java/org/apache/doris/analysis/DecimalLiteral.java | 3 +++
.../rewrite/ExtractCommonFactorsRuleFunctionTest.java | 4 ++--
.../datatype_p0/decimalv3/test_decimalv3_where.out | 6 ++++++
.../datatype_p0/decimalv3/test_decimalv3_where.groovy | 18 ++++++++++++++++++
4 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java
index ae0a31c2f43..3a3a8f8f66a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java
@@ -306,6 +306,9 @@ public class DecimalLiteral extends LiteralExpr {
int integerPart = Math.max(this.value.precision() - this.value.scale(),
type.getPrecision() - ((ScalarType) type).decimalScale());
this.type = ScalarType.createDecimalV3Type(integerPart + scale, scale);
+ BigDecimal adjustedValue = value.scale() < 0 ? value
+ : value.setScale(scale, RoundingMode.HALF_UP);
+ this.value = Objects.requireNonNull(adjustedValue);
}
}
diff --git a/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java
index 1fcffc4fa5c..3c55d248544 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java
@@ -259,8 +259,8 @@ public class ExtractCommonFactorsRuleFunctionTest {
Assert.assertTrue(planString.contains("`l_partkey` = `p_partkey`"));
Assert.assertTrue(planString.contains("`l_shipmode` IN ('AIR', 'AIR REG')"));
Assert.assertTrue(planString.contains("`l_shipinstruct` = 'DELIVER IN PERSON'"));
- Assert.assertTrue(planString.contains("`l_quantity` >= 9 AND `l_quantity` <= 19 "
- + "OR `l_quantity` >= 20 AND `l_quantity` <= 36"));
+ Assert.assertTrue(planString.contains("`l_quantity` >= 9.00 AND `l_quantity` <= 19.00 "
+ + "OR `l_quantity` >= 20.00 AND `l_quantity` <= 36.00"));
Assert.assertTrue(planString.contains("`p_size` >= 1"));
Assert.assertTrue(planString.contains("`p_brand` IN ('Brand#11', 'Brand#21', 'Brand#32')"));
Assert.assertTrue(planString.contains("`p_size` <= 15"));
diff --git a/regression-test/data/datatype_p0/decimalv3/test_decimalv3_where.out b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_where.out
index 36084d4d211..bd3a5c0a98a 100644
--- a/regression-test/data/datatype_p0/decimalv3/test_decimalv3_where.out
+++ b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_where.out
@@ -4,3 +4,9 @@
2 spark 10 96
1 doris 20 324
+-- !select --
+1.00100 2.00200
+
+-- !select_after_update --
+1.00100 0.00010
+
diff --git a/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_where.groovy b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_where.groovy
index 287a77cbd10..2f83e07729d 100644
--- a/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_where.groovy
+++ b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_where.groovy
@@ -23,4 +23,22 @@ suite("test_decimalv3_where") {
sql """CREATE TABLE ${tableName} ( `id` varchar(11) NULL COMMENT '唯一标识', `name` varchar(10) NULL COMMENT '采集时间', `age` int(11) NULL, `dr` decimalv3(10, 0) ) ENGINE=OLAP UNIQUE KEY(`id`) COMMENT 'test' DISTRIBUTED BY HASH(`id`) BUCKETS 10 PROPERTIES ( "replication_allocation" = "tag.location.default: 1", "in_memory" = "false", "storage_format" = "V2", "light_schema_change" = "true", "disable_auto_compaction" = "false" );"""
sql """insert into ${tableName} values (1,'doris',20,324.10),(2,'spark',10,95.5),(3,'flink',9,20)"""
qt_decimalv3 "select * from ${tableName} where dr != 1 order by age;"
+
+ sql """set enable_nereids_planner=false;"""
+ sql """drop table if exists test_sys_update_basic_test_update_decimal_tb"""
+ sql """CREATE TABLE test_sys_update_basic_test_update_decimal_tb (
+ k1 DECIMAL(10, 5) NULL,
+ v1 DECIMAL(10, 5) NULL
+ ) UNIQUE KEY(k1) DISTRIBUTED BY HASH(k1) BUCKETS 5 PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1"
+ );"""
+ sql """insert into test_sys_update_basic_test_update_decimal_tb values
+ (1.001, 2.002), (1.002, 0.00000002), (1.003, 0.100000001), (1.004, 0.100044001), (1.005, 0.100045001);"""
+ qt_select """select * from test_sys_update_basic_test_update_decimal_tb where k1 = 1.001;"""
+ sql """
+ UPDATE test_sys_update_basic_test_update_decimal_tb SET v1=0.0001 WHERE k1 = 1.001;
+ """
+ qt_select_after_update """
+ select * from test_sys_update_basic_test_update_decimal_tb where k1 = 1.001;
+ """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org