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 a7e1660dd0..ecc394e499 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 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 40c576b1c4..6fe7fe7578 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 dc94074cac..36de26fc49 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 @@ -783,26 +783,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 6f125217ee..60d1980d28 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 0000000000..76418ce38e --- /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 Yes false \N NONE +c2 DECIMAL(12, 1) Yes false \N NONE +c3 MAP Yes false \N NONE +c4 STRUCT Yes false \N NONE + +-- !sql -- +id INT Yes true \N +c1 ARRAY Yes false \N NONE +c2 DECIMAL(12, 1) Yes false \N NONE +c3 MAP Yes false \N NONE +c4 STRUCT 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 04812eb79b..7867c17559 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 Yes false \N NONE arr_largeint_col ARRAY Yes false \N NONE arr_float_col ARRAY Yes false \N NONE arr_double_col ARRAY Yes false \N NONE -arr_decimal1_col ARRAY Yes false \N NONE -arr_decimal2_col ARRAY Yes false \N NONE -arr_date_col ARRAY Yes false \N NONE -arr_datetime_col ARRAY Yes false \N NONE +arr_decimal1_col ARRAY Yes false \N NONE +arr_decimal2_col ARRAY Yes false \N NONE +arr_date_col ARRAY Yes false \N NONE +arr_datetime_col ARRAY Yes false \N NONE arr_char_col ARRAY Yes false \N NONE arr_varchar_col ARRAY Yes false \N NONE arr_string_col ARRAY 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 06a38d5751..d835e1c0c4 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 b7becd6cdf..29036aa342 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 0000000000..ec5f620794 --- /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 NULL, + `c2` DECIMALV3(12, 1) NULL, + `c3` MAP NULL, + `c4` STRUCT 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')) +}