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 4f3b4c7efc [Improvement] information_schema.columns support COLUMN KEY (#11228) 4f3b4c7efc is described below commit 4f3b4c7efc0c8dfd10651698c010553b7be48f7a Author: Stalary <stal...@163.com> AuthorDate: Wed Jul 27 12:22:17 2022 +0800 [Improvement] information_schema.columns support COLUMN KEY (#11228) --- .../exec/schema_scanner/schema_columns_scanner.cpp | 14 +++++++-- .../java/org/apache/doris/catalog/KeysType.java | 33 ++++++++++++++++++++++ .../apache/doris/service/FrontendServiceImpl.java | 5 ++++ gensrc/thrift/FrontendService.thrift | 1 + .../data/account/test_information_schema.out | 3 ++ .../suites/account/test_information_schema.groovy | 3 ++ 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/be/src/exec/schema_scanner/schema_columns_scanner.cpp b/be/src/exec/schema_scanner/schema_columns_scanner.cpp index bfa2c93e24..6102e128af 100644 --- a/be/src/exec/schema_scanner/schema_columns_scanner.cpp +++ b/be/src/exec/schema_scanner/schema_columns_scanner.cpp @@ -343,9 +343,17 @@ Status SchemaColumnsScanner::fill_one_row(Tuple* tuple, MemPool* pool) { { void* slot = tuple->get_slot(_tuple_desc->slots()[16]->tuple_offset()); StringValue* str_slot = reinterpret_cast<StringValue*>(slot); - str_slot->len = strlen("") + 1; - str_slot->ptr = (char*)pool->allocate(str_slot->len); - memcpy(str_slot->ptr, "", str_slot->len); + if (_desc_result.columns[_column_index].columnDesc.__isset.columnKey) { + str_slot->len = _desc_result.columns[_column_index].columnDesc.columnKey.length(); + str_slot->ptr = (char*)pool->allocate( + _desc_result.columns[_column_index].columnDesc.columnKey.length()); + memcpy(str_slot->ptr, _desc_result.columns[_column_index].columnDesc.columnKey.c_str(), + str_slot->len); + } else { + str_slot->len = strlen("") + 1; + str_slot->ptr = (char*)pool->allocate(str_slot->len); + memcpy(str_slot->ptr, "", str_slot->len); + } } // EXTRA { diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/KeysType.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/KeysType.java index cd2d1011e6..c280c522c3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/KeysType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/KeysType.java @@ -19,12 +19,18 @@ package org.apache.doris.catalog; import org.apache.doris.thrift.TKeysType; +/** + * Olap Table key type. + **/ public enum KeysType { PRIMARY_KEYS, DUP_KEYS, UNIQUE_KEYS, AGG_KEYS; + /** + * Determine whether it is an aggregation type. + **/ public boolean isAggregationFamily() { switch (this) { case AGG_KEYS: @@ -35,6 +41,9 @@ public enum KeysType { } } + /** + * Type convert to thrift. + **/ public TKeysType toThrift() { switch (this) { case PRIMARY_KEYS: @@ -50,6 +59,9 @@ public enum KeysType { } } + /** + * Type convert from thrift + **/ public static KeysType fromThrift(TKeysType tKeysType) { switch (tKeysType) { case PRIMARY_KEYS: @@ -65,6 +77,9 @@ public enum KeysType { } } + /** + * Type convert to sql. + **/ public String toSql() { switch (this) { case PRIMARY_KEYS: @@ -79,4 +94,22 @@ public enum KeysType { return null; } } + + /** + * Type convert to information_schema, try to be compatible with mysql. + **/ + public String toMetadata() { + switch (this) { + case PRIMARY_KEYS: + return "PRI"; + case DUP_KEYS: + return "DUP"; + case UNIQUE_KEYS: + return "UNI"; + case AGG_KEYS: + return "AGG"; + default: + return ""; + } + } } 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 55f49bd53a..48627907aa 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 @@ -427,6 +427,11 @@ public class FrontendServiceImpl implements FrontendService.Iface { if (comment != null) { colDef.setComment(comment); } + if (column.isKey()) { + if (table instanceof OlapTable) { + desc.setColumnKey(((OlapTable) table).getKeysType().toMetadata()); + } + } columns.add(colDef); } } finally { diff --git a/gensrc/thrift/FrontendService.thrift b/gensrc/thrift/FrontendService.thrift index a21452a5ab..5765e87da1 100644 --- a/gensrc/thrift/FrontendService.thrift +++ b/gensrc/thrift/FrontendService.thrift @@ -49,6 +49,7 @@ struct TColumnDesc { 4: optional i32 columnPrecision 5: optional i32 columnScale 6: optional bool isAllowNull + 7: optional string columnKey } // A column definition; used by CREATE TABLE and DESCRIBE <table> statements. A column diff --git a/regression-test/data/account/test_information_schema.out b/regression-test/data/account/test_information_schema.out index 1e6a3994f3..a5d980bc08 100644 --- a/regression-test/data/account/test_information_schema.out +++ b/regression-test/data/account/test_information_schema.out @@ -29,3 +29,6 @@ -- !sql -- 476 +-- !sql -- +DUP + diff --git a/regression-test/suites/account/test_information_schema.groovy b/regression-test/suites/account/test_information_schema.groovy index 71c89c6f58..6483e38616 100644 --- a/regression-test/suites/account/test_information_schema.groovy +++ b/regression-test/suites/account/test_information_schema.groovy @@ -88,6 +88,9 @@ suite("test_information_schema", "columns") { qt_sql "SELECT COUNT(*) FROM `columns` WHERE TABLE_SCHEMA='${dbName}'" } + sql "USE information_schema" + qt_sql "SELECT COLUMN_KEY FROM `columns` WHERE TABLE_SCHEMA='db_test_schema_1' and TABLE_NAME='tb_test_schema_1' and COLUMN_NAME='aaa'" + for (int i = 1; i <= 5; i++) { def dbName = dbPrefix + i.toString() sql "DROP DATABASE `${dbName}`" --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org