[Improvement] information_schema.columns support COLUMN KEY (#11228)

This commit is contained in:
Stalary
2022-07-27 12:22:17 +08:00
committed by GitHub
parent 2ed46eee64
commit 4f3b4c7efc
6 changed files with 56 additions and 3 deletions

View File

@ -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 "";
}
}
}

View File

@ -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 {