| 1422 | } |
| 1423 | |
| 1424 | LogicalType parseDecimalType(const std::string& trimmedStr) { |
| 1425 | auto leftBracketPos = trimmedStr.find_last_of('('); |
| 1426 | auto rightBracketPos = trimmedStr.find_last_of(')'); |
| 1427 | if (leftBracketPos == std::string::npos) { |
| 1428 | return LogicalType::DECIMAL(18, 3); |
| 1429 | } |
| 1430 | auto paramSubstr = StringUtils::ltrim(StringUtils::rtrim( |
| 1431 | trimmedStr.substr(leftBracketPos + 1, rightBracketPos - leftBracketPos - 1))); |
| 1432 | auto commaPos = paramSubstr.find_last_of(','); |
| 1433 | if (commaPos == std::string::npos) { |
| 1434 | throw BinderException("Only found 1 parameter for NUMERIC/DECIMAL type, expected 2"); |
| 1435 | } |
| 1436 | auto precisionStr = StringUtils::ltrim(StringUtils::rtrim(paramSubstr.substr(0, commaPos))); |
| 1437 | auto scaleStr = StringUtils::ltrim(StringUtils::rtrim(paramSubstr.substr(commaPos + 1))); |
| 1438 | auto precision = std::strtoll(precisionStr.c_str(), nullptr, 0); |
| 1439 | auto scale = std::strtoll(scaleStr.c_str(), nullptr, 0); |
| 1440 | if (precision <= 0 || precision > 38) { |
| 1441 | throw BinderException( |
| 1442 | "Precision of DECIMAL/NUMERIC must be a positive integer no greater than 38"); |
| 1443 | } |
| 1444 | if (scale < 0 || scale > precision) { |
| 1445 | throw BinderException( |
| 1446 | "Scale of DECIMAL/NUMERIC must be a nonnegative integer no greater than the precision"); |
| 1447 | } |
| 1448 | return LogicalType::DECIMAL((uint32_t)precision, (uint32_t)scale); |
| 1449 | } |
| 1450 | |
| 1451 | LogicalType LogicalType::DECIMAL(uint32_t precision, uint32_t scale) { |
| 1452 | return LogicalType(LogicalTypeID::DECIMAL, std::make_unique<DecimalTypeInfo>(precision, scale)); |
no test coverage detected