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 16, 2024
1 parent 43895d7 commit a465f31
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
13 changes: 8 additions & 5 deletions be/src/olap/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ bool valid_signed_number<int128_t>(const std::string& value_str) {
}

bool valid_decimal(const std::string& value_str, const uint32_t precision, const uint32_t frac) {
const char* decimal_pattern = "-?\\d+(.\\d+)?";
const char* decimal_pattern = "-?(\\d+)(.\\d+)?";
std::regex e(decimal_pattern);
std::smatch what;
if (!std::regex_match(value_str, what, e) || what[0].str().size() != value_str.size()) {
Expand All @@ -562,11 +562,14 @@ 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) {
if (what[1].str() == "0") {
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

16 changes: 13 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,22 @@ 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';
"""

sql """
delete from table_decimal where k4 = '-0.123';
"""

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

0 comments on commit a465f31

Please sign in to comment.