diff --git a/be/src/exec/schema_scanner/schema_columns_scanner.cpp b/be/src/exec/schema_scanner/schema_columns_scanner.cpp index 7848a7b528..56a6c5f256 100644 --- a/be/src/exec/schema_scanner/schema_columns_scanner.cpp +++ b/be/src/exec/schema_scanner/schema_columns_scanner.cpp @@ -239,6 +239,40 @@ std::string SchemaColumnsScanner::_type_to_string(TColumnDesc& desc) { case TPrimitiveType::JSONB: { return "json"; } + case TPrimitiveType::MAP: { + // for old be service we should compatible + std::string ret = "map<"; + if (!desc.children.empty()) { + for (int i = 0; i < desc.children.size() - 1; ++i) { + ret += _type_to_string(desc.children[i]) + ","; + } + ret += _type_to_string(desc.children[desc.children.size() - 1]); + } + ret += ">"; + return ret; + } + case TPrimitiveType::ARRAY: { + // for old be service we should compitable + std::string ret = "array<"; + if (!desc.children.empty()) { + ret += _type_to_string(desc.children[0]); + } + ret += ">"; + return ret; + } + case TPrimitiveType::STRUCT: { + // for old be service we should compitable + std::string ret = "struct<"; + if (!desc.children.empty()) { + for (int i = 0; i < desc.children.size() - 1; ++i) { + ret += _type_to_string(desc.children[i]) + ","; + } + ret += _type_to_string(desc.children[desc.children.size() - 1]); + } + ret += ">"; + return ret; + } + default: return "unknown"; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java index 6a99e38b15..c1e8e3e3f7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java +++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java @@ -1013,20 +1013,7 @@ public class FrontendServiceImpl implements FrontendService.Iface { try { List baseSchema = table.getBaseSchemaOrEmpty(); for (Column column : baseSchema) { - final TColumnDesc desc = new TColumnDesc(column.getName(), column.getDataType().toThrift()); - final Integer precision = column.getOriginType().getPrecision(); - if (precision != null) { - desc.setColumnPrecision(precision); - } - final Integer columnLength = column.getOriginType().getColumnSize(); - if (columnLength != null) { - desc.setColumnLength(columnLength); - } - final Integer decimalDigits = column.getOriginType().getDecimalDigits(); - if (decimalDigits != null) { - desc.setColumnScale(decimalDigits); - } - desc.setIsAllowNull(column.isAllowNull()); + final TColumnDesc desc = getColumnDesc(column); final TColumnDef colDef = new TColumnDef(desc); final String comment = column.getComment(); if (comment != null) { @@ -1049,6 +1036,31 @@ public class FrontendServiceImpl implements FrontendService.Iface { return result; } + public TColumnDesc getColumnDesc(Column column) { + final TColumnDesc desc = new TColumnDesc(column.getName(), column.getDataType().toThrift()); + final Integer precision = column.getOriginType().getPrecision(); + if (precision != null) { + desc.setColumnPrecision(precision); + } + final Integer columnLength = column.getOriginType().getColumnSize(); + if (columnLength != null) { + desc.setColumnLength(columnLength); + } + final Integer decimalDigits = column.getOriginType().getDecimalDigits(); + if (decimalDigits != null) { + desc.setColumnScale(decimalDigits); + } + desc.setIsAllowNull(column.isAllowNull()); + if (column.getChildren().size() > 0) { + ArrayList children = new ArrayList<>(); + for (Column child : column.getChildren()) { + children.add(getColumnDesc(child)); + } + desc.setChildren(children); + } + return desc; + } + @Override public TShowVariableResult showVariables(TShowVariableRequest params) throws TException { TShowVariableResult result = new TShowVariableResult(); diff --git a/regression-test/data/datatype_p0/nested_types/meta/test_complextype_information_schema.out b/regression-test/data/datatype_p0/nested_types/meta/test_complextype_information_schema.out new file mode 100644 index 0000000000..4a6f66c4e2 --- /dev/null +++ b/regression-test/data/datatype_p0/nested_types/meta/test_complextype_information_schema.out @@ -0,0 +1,61 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +bigint bigint(20) +array array +array array +array array +array array +array array +array array +array array +array array +array array +array array +array array +array array +array array +array array +array array +array array +array array + +-- !sql -- +bigint bigint(20) +map map +map map +map map +map map +map map +map map +map map +map map +map map +map map +map map +map map +map map +map map +map map +map map +map map + +-- !sql -- +bigint bigint(20) +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct +struct struct + diff --git a/regression-test/suites/datatype_p0/nested_types/meta/test_complextype_information_schema.groovy b/regression-test/suites/datatype_p0/nested_types/meta/test_complextype_information_schema.groovy new file mode 100644 index 0000000000..9a99873287 --- /dev/null +++ b/regression-test/suites/datatype_p0/nested_types/meta/test_complextype_information_schema.groovy @@ -0,0 +1,32 @@ +// 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_information_schema") { + sql """set enable_nereids_planner=false""" + // add array/map/struct + def table_names = ["array_info", "map_info", "struct_info"] + for (int i = 0; i < table_names.size(); ++i) { + sql """ DROP TABLE IF EXISTS ${table_names[i]} """ + String result = create_table_with_nested_type(1, [i], table_names[i]) + sql result + } + + for (int i = 0; i < table_names.size(); ++i) { + sql "use information_schema" + qt_sql "select data_type, column_type from columns where TABLE_NAME=\"${table_names[i]}\";" + } +}