You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/10/20 00:57:04 UTC
[doris] branch branch-1.1-lts updated: [Cherry-pick](information_schema) information_schema.columns support COLUMN KEY #13481
This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-1.1-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.1-lts by this push:
new 49ab86dd24 [Cherry-pick](information_schema) information_schema.columns support COLUMN KEY #13481
49ab86dd24 is described below
commit 49ab86dd24cd94dedf7d9ec3dbf7e7019d4890bb
Author: Stalary <st...@163.com>
AuthorDate: Thu Oct 20 08:56:59 2022 +0800
[Cherry-pick](information_schema) information_schema.columns support COLUMN KEY #13481
---
.../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 +
4 files changed, 50 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 390a0af5bc..f6607b06f3 100644
--- a/be/src/exec/schema_scanner/schema_columns_scanner.cpp
+++ b/be/src/exec/schema_scanner/schema_columns_scanner.cpp
@@ -341,9 +341,17 @@ Status SchemaColumnsScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
{
void* slot = tuple->get_slot(_tuple_desc->slots()[17]->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);
+ }
}
// PRIVILEGES
{
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 cf22842718..02dcdb52b9 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,5 +94,23 @@ 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 aac464cb99..eb7cc585bd 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
@@ -411,6 +411,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 923ba595fc..92de8e5fc8 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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org