[fix](delete) Incorrect precision detection for the decimal type in condition.​ (#37801) (#37904)

## Proposed changes

pick #37801

For precision like Decimal(7,7), the value "0.1234567" should be
valid(the integer part is 0).

## Proposed changes

Issue Number: close #xxx

<!--Describe your changes.-->
This commit is contained in:
Jerry Hu
2024-07-16 19:02:02 +08:00
committed by GitHub
parent 9861f81630
commit 8440303b91
3 changed files with 23 additions and 9 deletions

View File

@ -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()) {
@ -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) {

View File

@ -146,4 +146,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

View File

@ -518,7 +518,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
@ -529,12 +530,21 @@ 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;
"""