You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2023/04/19 03:34:34 UTC

[doris] branch master updated: [minor](decimal) forbid to create table with decimal type exceeds 18 (#18763)

This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 15529afed8 [minor](decimal) forbid to create table with decimal type exceeds 18 (#18763)
15529afed8 is described below

commit 15529afed831341395c12a9bad6200191305c613
Author: Gabriel <ga...@gmail.com>
AuthorDate: Wed Apr 19 11:34:27 2023 +0800

    [minor](decimal) forbid to create table with decimal type exceeds 18 (#18763)
    
    * [minor](decimal) forbid to create table with decimal type exceeds 18
    
    * update
---
 .../java/org/apache/doris/analysis/TypeDef.java    |  8 ++++++--
 .../account_p0/test_information_schema.groovy      |  6 +++---
 .../test_outer_join_with_subquery.groovy           | 24 +++++++++++-----------
 .../test_outer_join_with_inline_view.groovy        |  2 +-
 .../stream_load/test_parquet_orc_case.groovy       |  4 ++--
 .../suites/mysql_ssl_p0/test_ssl_wild.groovy       | 10 ++++-----
 .../test_array_aggregation_functions.groovy        |  2 +-
 .../test_array_aggregation_functions.groovy        |  2 +-
 8 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TypeDef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/TypeDef.java
index c75259050d..5eae5d57ba 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TypeDef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TypeDef.java
@@ -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."
diff --git a/regression-test/suites/account_p0/test_information_schema.groovy b/regression-test/suites/account_p0/test_information_schema.groovy
index 49f9fffb3e..dcbc0c3532 100644
--- a/regression-test/suites/account_p0/test_information_schema.groovy
+++ b/regression-test/suites/account_p0/test_information_schema.groovy
@@ -45,9 +45,9 @@ suite("test_information_schema") {
                 `qqq` varchar(130) NULL COMMENT "",
                 `rrr` bigint(20) NULL COMMENT "",
                 `sss` bigint(20) NULL COMMENT "",
-                `ttt` decimal(24, 2) NULL COMMENT "",
-                `uuu` decimal(24, 2) NULL COMMENT "",
-                `vvv` decimal(24, 2) NULL COMMENT "",
+                `ttt` decimal(20, 2) NULL COMMENT "",
+                `uuu` decimal(20, 2) NULL COMMENT "",
+                `vvv` decimal(20, 2) NULL COMMENT "",
                 `www` varchar(50) NULL COMMENT "",
                 `xxx` varchar(190) NULL COMMENT "",
                 `yyy` varchar(190) NULL COMMENT "",
diff --git a/regression-test/suites/correctness/test_outer_join_with_subquery.groovy b/regression-test/suites/correctness/test_outer_join_with_subquery.groovy
index 1471f6965a..fd2ce0b7e8 100644
--- a/regression-test/suites/correctness/test_outer_join_with_subquery.groovy
+++ b/regression-test/suites/correctness/test_outer_join_with_subquery.groovy
@@ -44,21 +44,21 @@
             `datatimev2_2`           datetimev2(3) NOT NULL COMMENT "",
             `datatimev2_3`           datetimev2(6) NOT NULL COMMENT "",
             `employee`               int(11) NULL COMMENT "",
-            `oper_rev`               decimal(27, 2) NULL COMMENT "",
-            `net_profit`             decimal(27, 2) NULL COMMENT "",
-            `roe_diluted`            decimal(27, 2) NULL COMMENT "",
-            `roe_forecast1`          decimal(27, 2) NULL COMMENT "",
-            `roe_forecast2`          decimal(27, 2) NULL COMMENT "",
-            `roe_forecast3`          decimal(27, 2) NULL COMMENT "",
+            `oper_rev`               decimal(20, 2) NULL COMMENT "",
+            `net_profit`             decimal(20, 2) NULL COMMENT "",
+            `roe_diluted`            decimal(20, 2) NULL COMMENT "",
+            `roe_forecast1`          decimal(20, 2) NULL COMMENT "",
+            `roe_forecast2`          decimal(20, 2) NULL COMMENT "",
+            `roe_forecast3`          decimal(20, 2) NULL COMMENT "",
             `segment_sales_industry` varchar(2000) NULL COMMENT "",
             `segment_sales_product`  varchar(2000) NULL COMMENT "",
             `segment_sales_region`   varchar(2000) NULL COMMENT "",
-            `cont_liab`              decimal(27, 2) NULL COMMENT "",
-            `rd_exp`                 decimal(27, 2) NULL COMMENT "",
-            `cash_end_bal_cf`        decimal(27, 2) NULL COMMENT "",
-            `deductedprofit`         decimal(27, 2) NULL COMMENT "",
-            `extraordinary`          decimal(27, 2) NULL COMMENT "",
-            `capex`                  decimal(27, 2) NULL COMMENT "",
+            `cont_liab`              decimal(20, 2) NULL COMMENT "",
+            `rd_exp`                 decimal(20, 2) NULL COMMENT "",
+            `cash_end_bal_cf`        decimal(20, 2) NULL COMMENT "",
+            `deductedprofit`         decimal(20, 2) NULL COMMENT "",
+            `extraordinary`          decimal(20, 2) NULL COMMENT "",
+            `capex`                  decimal(20, 2) NULL COMMENT "",
             `update_time`            datetime NULL COMMENT ""
         ) ENGINE=OLAP
         UNIQUE KEY(`stock_code`, `data_time`, `datev2`, `datatimev2_1`, `datatimev2_2`, `datatimev2_3`)
diff --git a/regression-test/suites/correctness_p0/test_outer_join_with_inline_view.groovy b/regression-test/suites/correctness_p0/test_outer_join_with_inline_view.groovy
index 16f02a39bf..3d8c563f0d 100644
--- a/regression-test/suites/correctness_p0/test_outer_join_with_inline_view.groovy
+++ b/regression-test/suites/correctness_p0/test_outer_join_with_inline_view.groovy
@@ -115,7 +115,7 @@ suite("test_outer_join_with_inline_view") {
     sql """
         CREATE TABLE `subquery_table_3` (
         `org_code` varchar(96) NULL, 
-        `bo_ql_in_advance` decimal(27, 6) NULL
+        `bo_ql_in_advance` decimal(24, 6) NULL
         ) ENGINE=OLAP
         DUPLICATE KEY(`org_code`)
         COMMENT 'OLAP'
diff --git a/regression-test/suites/load_p0/stream_load/test_parquet_orc_case.groovy b/regression-test/suites/load_p0/stream_load/test_parquet_orc_case.groovy
index fac1ddabc4..22e61893ed 100644
--- a/regression-test/suites/load_p0/stream_load/test_parquet_orc_case.groovy
+++ b/regression-test/suites/load_p0/stream_load/test_parquet_orc_case.groovy
@@ -211,7 +211,7 @@ suite("test_parquet_orc_case", "p0") {
     sql """ DROP TABLE IF EXISTS ${arrayParquetTbl} """
 
     sql """
-    CREATE TABLE ${arrayParquetTbl} ( 
+    CREATE TABLE ${arrayParquetTbl} (
         k1 int NULL, 
         a1 array<boolean> NULL, 
         a2 array<tinyint> NULL, 
@@ -219,7 +219,7 @@ suite("test_parquet_orc_case", "p0") {
         a4 array<int> NULL, 
         a5 array<bigint> NULL, 
         a6 array<largeint> NULL,
-        a7 array<decimal(27, 7)> NULL, 
+        a7 array<decimal(25, 7)> NULL,
         a8 array<float> NULL, 
         a9 array<double> NULL, 
         a10 array<date> NULL, 
diff --git a/regression-test/suites/mysql_ssl_p0/test_ssl_wild.groovy b/regression-test/suites/mysql_ssl_p0/test_ssl_wild.groovy
index 3e7147698c..a9c3620b1d 100644
--- a/regression-test/suites/mysql_ssl_p0/test_ssl_wild.groovy
+++ b/regression-test/suites/mysql_ssl_p0/test_ssl_wild.groovy
@@ -46,7 +46,7 @@ suite("test_ssl_wild") {
                 col22 text NULL,
                 col23 text NULL,
                 col24 int(11) NULL,
-                col25 decimal(22, 2) NULL,
+                col25 decimal(20, 2) NULL,
                 col26 decimal(22, 4) NULL,
                 col27 decimal(16, 8) NULL,
                 col28 decimal(16, 8) NULL,
@@ -70,10 +70,10 @@ suite("test_ssl_wild") {
                 col46 decimal(16, 2) NULL,
                 col47 int(11) NULL,
                 col48 decimal(16, 2) NULL,
-                col49 decimal(22, 2) NULL,
-                col50 decimal(22, 2) NULL,
-                col51 decimal(22, 2) NULL,
-                col52 decimal(22, 2) NULL,
+                col49 decimal(20, 2) NULL,
+                col50 decimal(20, 2) NULL,
+                col51 decimal(20, 2) NULL,
+                col52 decimal(20, 2) NULL,
                 col53 decimal(16, 2) NULL,
                 col54 int(11) NULL,
                 col55 int(11) NULL,
diff --git a/regression-test/suites/nereids_p0/sql_functions/array_functions/test_array_aggregation_functions.groovy b/regression-test/suites/nereids_p0/sql_functions/array_functions/test_array_aggregation_functions.groovy
index e904c7002b..f1ba1d0bfd 100644
--- a/regression-test/suites/nereids_p0/sql_functions/array_functions/test_array_aggregation_functions.groovy
+++ b/regression-test/suites/nereids_p0/sql_functions/array_functions/test_array_aggregation_functions.groovy
@@ -29,7 +29,7 @@ suite("test_array_aggregation_functions") {
               `a3` array<int(11)> NULL COMMENT "",
               `a4` array<bigint(20)> NULL COMMENT "",
               `a5` array<largeint(40)> NULL COMMENT "",
-              `a6` array<decimal(27, 7)> NULL COMMENT "",
+              `a6` array<decimal(25, 7)> NULL COMMENT "",
               `a7` array<float> NULL COMMENT "",
               `a8` array<double> NULL COMMENT "",
               `a9` array<date> NULL COMMENT "",
diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_aggregation_functions.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_aggregation_functions.groovy
index de827daa43..d6fe42b659 100644
--- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_aggregation_functions.groovy
+++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_aggregation_functions.groovy
@@ -27,7 +27,7 @@ suite("test_array_aggregation_functions") {
               `a3` array<int(11)> NULL COMMENT "",
               `a4` array<bigint(20)> NULL COMMENT "",
               `a5` array<largeint(40)> NULL COMMENT "",
-              `a6` array<decimal(27, 7)> NULL COMMENT "",
+              `a6` array<decimal(25, 7)> NULL COMMENT "",
               `a7` array<float> NULL COMMENT "",
               `a8` array<double> NULL COMMENT "",
               `a9` array<date> NULL COMMENT "",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org