Skip to content

Commit

Permalink
[fix](delete) Incorrect precision detection for the decimal type in c…
Browse files Browse the repository at this point in the history
…ondition.​
  • Loading branch information
mrhhsg committed Jul 15, 2024
1 parent 43895d7 commit a765d1e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
13 changes: 9 additions & 4 deletions be/src/olap/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,16 @@ bool valid_decimal(const std::string& value_str, const uint32_t precision, const
fractional_len = number_length - point_pos - 1;
}

if (integer_len <= (precision - frac) && fractional_len <= frac) {
return true;
} else {
return false;
/// For value likes "0.xxxxxx", the integer_len should actually be 0.
if (integer_len == 1 && precision - frac == 0) {
const char* zero_leading_pattern = "-?0(\\.\\d+)?";
std::regex re(zero_leading_pattern);
if (std::regex_match(value_str, what, re)) {
integer_len = 0;
}
}

return (integer_len <= (precision - frac) && fractional_len <= frac);
}

bool valid_datetime(const std::string& value_str, const uint32_t scale) {
Expand Down
3 changes: 2 additions & 1 deletion regression-test/data/delete_p0/test_delete.out
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ ccc ccc
43 44 46 47 135.200 g t 2023-02-14 2023-02-14T00:01:02 false 22240.106 rr

-- !check_decimal --
true -1.0 10
true -1.0 10 0.7654321

12 changes: 9 additions & 3 deletions regression-test/suites/delete_p0/test_delete.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ suite("test_delete") {
CREATE TABLE table_decimal (
`k1` BOOLEAN NOT NULL,
`k2` DECIMAL(17, 1) NOT NULL,
`k3` INT NOT NULL
`k3` INT NOT NULL,
`k4` DECIMAL(7, 7)
) ENGINE=OLAP
DUPLICATE KEY(`k1`,`k2`,`k3`)
DISTRIBUTED BY HASH(`k1`,`k2`,`k3`) BUCKETS 4
Expand All @@ -535,13 +536,18 @@ suite("test_delete") {
"""
sql """
insert into table_decimal values
(false, '-9999782574499444.2', -20),
(true, '-1', 10);
(false, '-9999782574499444.2', -20, 0.1234567),
(true, '-1', 10, 0.7654321);
"""

sql """
delete from table_decimal where k1 = false and k2 = '-9999782574499444.2' and k3 = '-20';
"""

sql """
delete from table_decimal where k4 = '0.1234567';
"""

qt_check_decimal """
select * from table_decimal;
"""
Expand Down

0 comments on commit a765d1e

Please sign in to comment.