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 a23ccfde821 [FIX](complextype)fix complex type nested version type but 
not hide version (#30419)
a23ccfde821 is described below

commit a23ccfde8210b1e9a2ac9bab01224d11ba8e6418
Author: amory <[email protected]>
AuthorDate: Mon Jan 29 18:19:14 2024 +0800

    [FIX](complextype)fix complex type nested version type but not hide version 
(#30419)
---
 .../main/java/org/apache/doris/catalog/Type.java   | 42 +++++++++++++++++++
 .../org/apache/doris/analysis/DescribeStmt.java    | 21 +---------
 .../main/java/org/apache/doris/catalog/Column.java | 21 +---------
 .../doris/common/proc/IndexSchemaProcNode.java     | 24 +----------
 .../test_complextype_nested_version_schema.out     | 15 +++++++
 .../jdbc/test_doris_jdbc_catalog.out               |  8 ++--
 .../jdbc/test_oracle_jdbc_catalog.out              |  2 +-
 .../jdbc/test_sqlserver_jdbc_catalog.out           |  4 +-
 .../test_complextype_nested_version_schema.groovy  | 49 ++++++++++++++++++++++
 9 files changed, 116 insertions(+), 70 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java 
b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
index a7e1660dd02..ecc394e4990 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
@@ -30,6 +30,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -448,6 +449,47 @@ public abstract class Type {
         return false;
     }
 
+    public String hideVersionForVersionColumn(Boolean isToSql) {
+        if (isDatetimeV2()) {
+            StringBuilder typeStr = new StringBuilder("DATETIME");
+            if (((ScalarType) this).getScalarScale() > 0) {
+                typeStr.append("(").append(((ScalarType) 
this).getScalarScale()).append(")");
+            }
+            return typeStr.toString();
+        } else if (isDateV2()) {
+            return "DATE";
+        } else if (isDecimalV3()) {
+            StringBuilder typeStr = new StringBuilder("DECIMAL");
+            ScalarType sType = (ScalarType) this;
+            int scale = sType.getScalarScale();
+            int precision = sType.getScalarPrecision();
+            // not default
+            if (!sType.isDefaultDecimal()) {
+                typeStr.append("(").append(precision).append(", 
").append(scale)
+                        .append(")");
+            }
+            return typeStr.toString();
+        } else if (isArrayType()) {
+            String nestedDesc = ((ArrayType) 
this).getItemType().hideVersionForVersionColumn(isToSql);
+            return "ARRAY<" + nestedDesc + ">";
+        } else if (isMapType()) {
+            String keyDesc = ((MapType) 
this).getKeyType().hideVersionForVersionColumn(isToSql);
+            String valueDesc = ((MapType) 
this).getValueType().hideVersionForVersionColumn(isToSql);
+            return "MAP<" + keyDesc + "," + valueDesc + ">";
+        } else if (isStructType()) {
+            List<String> fieldDesc = new ArrayList<>();
+            StructType structType = (StructType) this;
+            for (int i = 0; i < structType.getFields().size(); i++) {
+                StructField field = structType.getFields().get(i);
+                fieldDesc.add(field.getName() + ":" + 
field.getType().hideVersionForVersionColumn(isToSql));
+            }
+            return "STRUCT<" + StringUtils.join(fieldDesc, ",") + ">";
+        } else if (isToSql) {
+            return this.toSql();
+        }
+        return this.toString();
+    }
+
     public boolean isDecimalV3OrContainsDecimalV3() {
         if (isDecimalV3()) {
             return true;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/DescribeStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DescribeStmt.java
index 40c576b1c4f..6fe7fe75780 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DescribeStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DescribeStmt.java
@@ -136,26 +136,7 @@ public class DescribeStmt extends ShowStmt {
                                 ? FeConstants.null_string : 
column.getDefaultValue(),
                         "NONE"
                 );
-                if (column.getOriginType().isDatetimeV2()) {
-                    StringBuilder typeStr = new StringBuilder("DATETIME");
-                    if (((ScalarType) column.getOriginType()).getScalarScale() 
> 0) {
-                        typeStr.append("(").append(((ScalarType) 
column.getOriginType()).getScalarScale()).append(")");
-                    }
-                    row.set(1, typeStr.toString());
-                } else if (column.getOriginType().isDateV2()) {
-                    row.set(1, "DATE");
-                } else if (column.getOriginType().isDecimalV3()) {
-                    StringBuilder typeStr = new StringBuilder("DECIMAL");
-                    ScalarType sType = (ScalarType) column.getOriginType();
-                    int scale = sType.getScalarScale();
-                    int precision = sType.getScalarPrecision();
-                    // not default
-                    if (scale > 0 && precision != 9) {
-                        typeStr.append("(").append(precision).append(", 
").append(scale)
-                                .append(")");
-                    }
-                    row.set(1, typeStr.toString());
-                }
+                row.set(1, 
column.getOriginType().hideVersionForVersionColumn(false));
                 totalRows.add(row);
             }
             return;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
index f83eb942ca6..395c3169ae4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
@@ -926,26 +926,7 @@ public class Column implements Writable, 
GsonPostProcessable {
 
         // show change datetimeV2/dateV2 to datetime/date
         if (isCompatible) {
-            if (type.isDatetimeV2()) {
-                sb.append("DATETIME");
-                if (((ScalarType) type).getScalarScale() > 0) {
-                    sb.append("(").append(((ScalarType) 
type).getScalarScale()).append(")");
-                }
-            } else if (type.isDateV2()) {
-                sb.append("DATE");
-            } else if (type.isDecimalV3()) {
-                sb.append("DECIMAL");
-                ScalarType sType = (ScalarType) type;
-                int scale = sType.getScalarScale();
-                int precision = sType.getScalarPrecision();
-                // not default
-                if (!sType.isDefaultDecimal()) {
-                    sb.append("(").append(precision).append(", ").append(scale)
-                            .append(")");
-                }
-            } else {
-                sb.append(typeStr);
-            }
+            sb.append(type.hideVersionForVersionColumn(true));
         } else {
             sb.append(typeStr);
         }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/proc/IndexSchemaProcNode.java
 
b/fe/fe-core/src/main/java/org/apache/doris/common/proc/IndexSchemaProcNode.java
index 6f125217ee1..60d1980d28b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/common/proc/IndexSchemaProcNode.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/common/proc/IndexSchemaProcNode.java
@@ -18,7 +18,6 @@
 package org.apache.doris.common.proc;
 
 import org.apache.doris.catalog.Column;
-import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.FeConstants;
 
@@ -76,28 +75,7 @@ public class IndexSchemaProcNode implements 
ProcNodeInterface {
                                                          ? 
FeConstants.null_string : column.getDefaultValue(),
                                                  extraStr);
 
-            if (column.getOriginType().isDateV2()) {
-                rowList.set(1, "DATE");
-            }
-            if (column.getOriginType().isDatetimeV2()) {
-                StringBuilder typeStr = new StringBuilder("DATETIME");
-                if (((ScalarType) column.getOriginType()).getScalarScale() > 
0) {
-                    typeStr.append("(").append(((ScalarType) 
column.getOriginType()).getScalarScale()).append(")");
-                }
-                rowList.set(1, typeStr.toString());
-            }
-            if (column.getOriginType().isDecimalV3()) {
-                StringBuilder typeStr = new StringBuilder("DECIMAL");
-                ScalarType sType = (ScalarType) column.getOriginType();
-                int scale = sType.getScalarScale();
-                int precision = sType.getScalarPrecision();
-                // not default
-                if (scale > 0 && precision != 9) {
-                    typeStr.append("(").append(precision).append(", 
").append(scale)
-                            .append(")");
-                }
-                rowList.set(1, typeStr.toString());
-            }
+            rowList.set(1, 
column.getOriginType().hideVersionForVersionColumn(false));
             result.addRow(rowList);
         }
         return result;
diff --git 
a/regression-test/data/datatype_p0/nested_types/meta/test_complextype_nested_version_schema.out
 
b/regression-test/data/datatype_p0/nested_types/meta/test_complextype_nested_version_schema.out
new file mode 100644
index 00000000000..76418ce38e1
--- /dev/null
+++ 
b/regression-test/data/datatype_p0/nested_types/meta/test_complextype_nested_version_schema.out
@@ -0,0 +1,15 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !sql --
+id     INT     Yes     true    \N      
+c1     ARRAY<DECIMAL(12, 1)>   Yes     false   \N      NONE
+c2     DECIMAL(12, 1)  Yes     false   \N      NONE
+c3     MAP<DECIMAL(12, 2),DATETIME>    Yes     false   \N      NONE
+c4     STRUCT<f1:DATE,f2:DATETIME,f3:DATE,f4:DATETIME,f5:DECIMAL>      Yes     
false   \N      NONE
+
+-- !sql --
+id     INT     Yes     true    \N      
+c1     ARRAY<DECIMAL(12, 1)>   Yes     false   \N      NONE
+c2     DECIMAL(12, 1)  Yes     false   \N      NONE
+c3     MAP<DECIMAL(12, 2),DATETIME>    Yes     false   \N      NONE
+c4     STRUCT<f1:DATE,f2:DATETIME,f3:DATE,f4:DATETIME,f5:DECIMAL>      Yes     
false   \N      NONE
+
diff --git 
a/regression-test/data/external_table_p0/jdbc/test_doris_jdbc_catalog.out 
b/regression-test/data/external_table_p0/jdbc/test_doris_jdbc_catalog.out
index 04812eb79ba..7867c17559e 100644
--- a/regression-test/data/external_table_p0/jdbc/test_doris_jdbc_catalog.out
+++ b/regression-test/data/external_table_p0/jdbc/test_doris_jdbc_catalog.out
@@ -104,10 +104,10 @@ arr_bigint_col    ARRAY<BIGINT>   Yes     false   \N      
NONE
 arr_largeint_col       ARRAY<LARGEINT> Yes     false   \N      NONE
 arr_float_col  ARRAY<FLOAT>    Yes     false   \N      NONE
 arr_double_col ARRAY<DOUBLE>   Yes     false   \N      NONE
-arr_decimal1_col       ARRAY<DECIMALV3(10, 5)> Yes     false   \N      NONE
-arr_decimal2_col       ARRAY<DECIMALV3(30, 10)>        Yes     false   \N      
NONE
-arr_date_col   ARRAY<DATEV2>   Yes     false   \N      NONE
-arr_datetime_col       ARRAY<DATETIMEV2(3)>    Yes     false   \N      NONE
+arr_decimal1_col       ARRAY<DECIMAL(10, 5)>   Yes     false   \N      NONE
+arr_decimal2_col       ARRAY<DECIMAL(30, 10)>  Yes     false   \N      NONE
+arr_date_col   ARRAY<DATE>     Yes     false   \N      NONE
+arr_datetime_col       ARRAY<DATETIME(3)>      Yes     false   \N      NONE
 arr_char_col   ARRAY<TEXT>     Yes     false   \N      NONE
 arr_varchar_col        ARRAY<TEXT>     Yes     false   \N      NONE
 arr_string_col ARRAY<TEXT>     Yes     false   \N      NONE
diff --git 
a/regression-test/data/external_table_p0/jdbc/test_oracle_jdbc_catalog.out 
b/regression-test/data/external_table_p0/jdbc/test_oracle_jdbc_catalog.out
index 06a38d57512..d835e1c0c48 100644
--- a/regression-test/data/external_table_p0/jdbc/test_oracle_jdbc_catalog.out
+++ b/regression-test/data/external_table_p0/jdbc/test_oracle_jdbc_catalog.out
@@ -184,7 +184,7 @@ INT_VALUE1  INT     Yes     false   \N      NONE
 INT_VALUE2     BIGINT  Yes     false   \N      NONE
 N1     TEXT    Yes     false   \N      NONE
 N2     LARGEINT        Yes     false   \N      NONE
-N3     DECIMAL Yes     false   \N      NONE
+N3     DECIMAL(9, 2)   Yes     false   \N      NONE
 N4     LARGEINT        Yes     false   \N      NONE
 N5     LARGEINT        Yes     false   \N      NONE
 N6     DECIMAL(5, 2)   Yes     false   \N      NONE
diff --git 
a/regression-test/data/external_table_p0/jdbc/test_sqlserver_jdbc_catalog.out 
b/regression-test/data/external_table_p0/jdbc/test_sqlserver_jdbc_catalog.out
index b7becd6cdf0..29036aa3429 100644
--- 
a/regression-test/data/external_table_p0/jdbc/test_sqlserver_jdbc_catalog.out
+++ 
b/regression-test/data/external_table_p0/jdbc/test_sqlserver_jdbc_catalog.out
@@ -81,8 +81,8 @@ bigint_value  BIGINT  Yes     false   \N      NONE
 real_value     FLOAT   Yes     false   \N      NONE
 float_value    DOUBLE  Yes     false   \N      NONE
 floatn_value   FLOAT   Yes     false   \N      NONE
-decimal_value  DECIMAL Yes     false   \N      NONE
-numeric_value  DECIMAL Yes     false   \N      NONE
+decimal_value  DECIMAL(38, 0)  Yes     false   \N      NONE
+numeric_value  DECIMAL(38, 0)  Yes     false   \N      NONE
 decimal_value2 DECIMAL(38, 10) Yes     false   \N      NONE
 numeric_value2 DECIMAL(38, 10) Yes     false   \N      NONE
 char_value     TEXT    Yes     false   \N      NONE
diff --git 
a/regression-test/suites/datatype_p0/nested_types/meta/test_complextype_nested_version_schema.groovy
 
b/regression-test/suites/datatype_p0/nested_types/meta/test_complextype_nested_version_schema.groovy
new file mode 100644
index 00000000000..ec5f6207940
--- /dev/null
+++ 
b/regression-test/suites/datatype_p0/nested_types/meta/test_complextype_nested_version_schema.groovy
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_complextype_nested_version_schema") {
+    sql """set enable_nereids_planner=true"""
+    // add array/map/struct
+    sql "DROP TABLE IF EXISTS `complext_nested_version`;"
+    def createTblSql = """
+    CREATE TABLE `complext_nested_version` (
+      `id` INT NULL,
+      `c1` ARRAY<DECIMALV3(12, 1)> NULL,
+      `c2` DECIMALV3(12, 1) NULL,
+      `c3` MAP<DECIMALV3(12, 2),DATETIMEV2> NULL,
+      `c4` STRUCT<f1:DATE,f2:DATETIME,f3:DATEV2,f4:DATETIMEV2,f5:DECIMALV3(9, 
0)> NULL
+    ) ENGINE=OLAP
+    DUPLICATE KEY(`id`)
+    COMMENT 'OLAP'
+    DISTRIBUTED BY HASH(`id`) BUCKETS 10
+    PROPERTIES ("replication_allocation" = "tag.location.default: 1"); """
+
+    sql createTblSql
+
+    qt_sql """ desc complext_nested_version ;"""
+    String res = sql """ show create table complext_nested_version ;"""
+    assertTrue(!res.contains('DECIMALV3'))
+    assertTrue(!res.contains('DATEV2'))
+    assertTrue(!res.contains('DATETIMEV2'))
+
+    sql """set enable_nereids_planner=false"""
+    qt_sql """ desc complext_nested_version ;"""
+    String res2 = sql """ show create table complext_nested_version ;"""
+    assertTrue(!res2.contains('DECIMALV3'))
+    assertTrue(!res2.contains('DATEV2'))
+    assertTrue(!res2.contains('DATETIMEV2'))
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to