[minor](decimal) forbid to create table with decimal type exceeds 18 (#18763)

* [minor](decimal) forbid to create table with decimal type exceeds 18

* update
This commit is contained in:
Gabriel
2023-04-19 11:34:27 +08:00
committed by GitHub
parent 0b379de602
commit 15529afed8
8 changed files with 31 additions and 27 deletions

View File

@ -194,15 +194,19 @@ public class TypeDef implements ParseNode {
int precision = scalarType.decimalPrecision();
int scale = scalarType.decimalScale();
// precision: [1, 27]
if (precision < 1 || precision > 27) {
if (precision < 1 || precision > ScalarType.MAX_DECIMALV2_PRECISION) {
throw new AnalysisException("Precision of decimal must between 1 and 27."
+ " Precision was set to: " + precision + ".");
}
// scale: [0, 9]
if (scale < 0 || scale > 9) {
if (scale < 0 || scale > ScalarType.MAX_DECIMALV2_SCALE) {
throw new AnalysisException(
"Scale of decimal must between 0 and 9." + " Scale was set to: " + scale + ".");
}
if (precision - scale > ScalarType.MAX_DECIMALV2_PRECISION - ScalarType.MAX_DECIMALV2_SCALE) {
throw new AnalysisException("Invalid decimal type with precision = " + precision + ", scale = "
+ scale);
}
// scale < precision
if (scale > precision) {
throw new AnalysisException("Scale of decimal must be smaller than precision."