Skip to content

Commit

Permalink
[fix](planner)decimalv3 literal's precision and scale is not correctl…
Browse files Browse the repository at this point in the history
…y set (#32288)
  • Loading branch information
starocean999 authored Mar 19, 2024
1 parent 2d18656 commit af4b422
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ protected void compactForLiteral(Type type) throws AnalysisException {
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ public void testComplexQuery() throws Exception {
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
2 spark 10 96
1 doris 20 324

-- !select --
1.00100 2.00200

-- !select_after_update --
1.00100 0.00010

Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,23 @@ 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;
"""
}

0 comments on commit af4b422

Please sign in to comment.