This is an automated email from the ASF dual-hosted git repository. lijibing 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 5ff94a1149d [improvement](information_schema)Support show default value in information_schema. (#44849) 5ff94a1149d is described below commit 5ff94a1149dea8c736873c716a490e3bab59bd39 Author: James <lijib...@selectdb.com> AuthorDate: Fri Dec 6 10:48:26 2024 +0800 [improvement](information_schema)Support show default value in information_schema. (#44849) ### What problem does this PR solve? The COLUMN_DEFAULT column in INFORMATION_SCHEMA.COLUMNS table is always NULL, this PR set the correct default value for COLUMN_DEFAULT. Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None --- .../exec/schema_scanner/schema_columns_scanner.cpp | 14 +++++++++++++- .../apache/doris/service/FrontendServiceImpl.java | 4 ++++ gensrc/thrift/FrontendService.thrift | 1 + .../data/account_p0/test_information_schema.out | 7 +++++++ .../account_p0/test_information_schema.groovy | 22 ++++++++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/be/src/exec/schema_scanner/schema_columns_scanner.cpp b/be/src/exec/schema_scanner/schema_columns_scanner.cpp index 8325a7f5dc4..b60dfc3d203 100644 --- a/be/src/exec/schema_scanner/schema_columns_scanner.cpp +++ b/be/src/exec/schema_scanner/schema_columns_scanner.cpp @@ -450,7 +450,19 @@ Status SchemaColumnsScanner::_fill_block_impl(vectorized::Block* block) { RETURN_IF_ERROR(fill_dest_column_for_range(block, 4, datas)); } // COLUMN_DEFAULT - { RETURN_IF_ERROR(fill_dest_column_for_range(block, 5, null_datas)); } + { + std::vector<StringRef> strs(columns_num); + for (int i = 0; i < columns_num; ++i) { + if (_desc_result.columns[i].columnDesc.__isset.defaultValue) { + strs[i] = StringRef(_desc_result.columns[i].columnDesc.defaultValue.c_str(), + _desc_result.columns[i].columnDesc.defaultValue.length()); + datas[i] = strs.data() + i; + } else { + datas[i] = nullptr; + } + } + RETURN_IF_ERROR(fill_dest_column_for_range(block, 5, datas)); + } // IS_NULLABLE { StringRef str_yes = StringRef("YES", 3); 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 cf9e8e82ce1..1ad8d733dde 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 @@ -972,6 +972,10 @@ public class FrontendServiceImpl implements FrontendService.Iface { } desc.setChildren(children); } + String defaultValue = column.getDefaultValue(); + if (defaultValue != null) { + desc.setDefaultValue(defaultValue); + } return desc; } diff --git a/gensrc/thrift/FrontendService.thrift b/gensrc/thrift/FrontendService.thrift index 246cc999562..916885028ad 100644 --- a/gensrc/thrift/FrontendService.thrift +++ b/gensrc/thrift/FrontendService.thrift @@ -53,6 +53,7 @@ struct TColumnDesc { 6: optional bool isAllowNull 7: optional string columnKey 8: optional list<TColumnDesc> children + 9: optional string defaultValue } // A column definition; used by CREATE TABLE and DESCRIBE <table> statements. A column diff --git a/regression-test/data/account_p0/test_information_schema.out b/regression-test/data/account_p0/test_information_schema.out index 77d5f6dccd5..e4f0ed09d0e 100644 --- a/regression-test/data/account_p0/test_information_schema.out +++ b/regression-test/data/account_p0/test_information_schema.out @@ -17,3 +17,10 @@ -- !sql -- DUP +-- !default -- +id largeint YES \N +name varchar(20) YES 无 +age smallint(6) YES 0 +address varchar(100) YES beijing +date datetime YES 20240101 + diff --git a/regression-test/suites/account_p0/test_information_schema.groovy b/regression-test/suites/account_p0/test_information_schema.groovy index dcbc0c35328..fc94ad4b9bc 100644 --- a/regression-test/suites/account_p0/test_information_schema.groovy +++ b/regression-test/suites/account_p0/test_information_schema.groovy @@ -87,4 +87,26 @@ suite("test_information_schema") { def dbName = dbPrefix + i.toString() sql "DROP DATABASE `${dbName}`" } + + def dbName = dbPrefix + "default" + def tableName = tablePrefix + "default" + sql "CREATE DATABASE IF NOT EXISTS `${dbName}`" + sql "USE `${dbName}`" + sql """drop table if exists `${tableName}`""" + sql """ + CREATE TABLE `${tableName}` ( + `id` largeint NULL COMMENT '用户ID', + `name` varchar(20) NULL DEFAULT "无" COMMENT '用户姓名', + `age` smallint NULL DEFAULT "0" COMMENT '用户年龄', + `address` varchar(100) NULL DEFAULT "beijing" COMMENT '用户所在地区', + `date` datetime NULL DEFAULT "20240101" COMMENT '数据导入时间' + ) ENGINE=OLAP + DUPLICATE KEY(`id`, `name`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1") + """ + qt_default "SELECT COLUMN_NAME as field,COLUMN_TYPE as type,IS_NULLABLE as isNullable, COLUMN_DEFAULT as defaultValue FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '${tableName}' AND TABLE_SCHEMA = '${dbName}'" + sql "DROP DATABASE `${dbName}`" } + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org