Skip to content

Commit

Permalink
[Enhancement] Support use table_name to filter scan in information_sc…
Browse files Browse the repository at this point in the history
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <[email protected]>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
  • Loading branch information
HangyuanLiu committed May 10, 2024
1 parent 187d87e commit 71d72ed
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
10 changes: 10 additions & 0 deletions be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,22 @@ Status SchemaTablesScanner::start(RuntimeState* state) {
TGetTablesInfoRequest get_tables_info_request;
get_tables_info_request.__set_auth_info(auth_info);

<<<<<<< HEAD:be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp
if (nullptr != _param->ip && 0 != _param->port) {
RETURN_IF_ERROR(SchemaHelper::get_tables_info(*(_param->ip), _param->port, get_tables_info_request,
&_tabls_info_response));
} else {
return Status::InternalError("IP or port doesn't exists");
}
=======
if (nullptr != _param->table) {
get_tables_info_request.__set_table_name(*(_param->table));
}

// init schema scanner state
RETURN_IF_ERROR(SchemaScanner::init_schema_scanner_state(state));
RETURN_IF_ERROR(SchemaHelper::get_tables_info(_ss_state, get_tables_info_request, &_tabls_info_response));
>>>>>>> 948e48f281 ([Enhancement] Support use table_name to filter scan in information_schema.tables (#45351)):be/src/exec/schema_scanner/schema_tables_scanner.cpp
return Status::OK();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import java.util.Set;

public class InformationSchemaDataSource {

private static final Logger LOG = LogManager.getLogger(InformationSchemaDataSource.class);

private static final String DEF = "def";
Expand Down Expand Up @@ -106,7 +106,7 @@ public AuthDbRequestResult(List<String> authorizedDbs, UserIdentity currentUser)

// tables_config
public static TGetTablesConfigResponse generateTablesConfigResponse(TGetTablesConfigRequest request) throws TException {

TGetTablesConfigResponse resp = new TGetTablesConfigResponse();
List<TTableConfigInfo> tList = new ArrayList<>();

Expand All @@ -128,8 +128,8 @@ public static TGetTablesConfigResponse generateTablesConfigResponse(TGetTablesCo
TTableConfigInfo tableConfigInfo = new TTableConfigInfo();
tableConfigInfo.setTable_schema(dbName);
tableConfigInfo.setTable_name(table.getName());
if (table.isOlapOrLakeTable() ||

if (table.isOlapOrLakeTable() ||
table.getType() == TableType.OLAP_EXTERNAL ||
table.getType() == TableType.MATERIALIZED_VIEW) {
// OLAP (done)
Expand All @@ -143,14 +143,13 @@ public static TGetTablesConfigResponse generateTablesConfigResponse(TGetTablesCo
}
} finally {
db.readUnlock();
}
}
}
}
}
resp.tables_config_infos = tList;
return resp;
}


private static Map<String, String> genProps(Table table) {

if (table.getType() == TableType.MATERIALIZED_VIEW) {
Expand All @@ -159,10 +158,10 @@ private static Map<String, String> genProps(Table table) {
}

OlapTable olapTable = (OlapTable) table;
Map<String, String> propsMap = new HashMap<>();
Map<String, String> propsMap = new HashMap<>();

propsMap.put(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM, String.valueOf(olapTable.getDefaultReplicationNum()));

// bloom filter
Set<String> bfColumnNames = olapTable.getCopiedBfColumns();
if (bfColumnNames != null) {
Expand All @@ -186,22 +185,22 @@ private static Map<String, String> genProps(Table table) {
// enable storage cache && cache ttl
if (table.isLakeTable()) {
Map<String, String> storageProperties = ((LakeTable) olapTable).getProperties();
propsMap.put(PropertyAnalyzer.PROPERTIES_ENABLE_STORAGE_CACHE,
propsMap.put(PropertyAnalyzer.PROPERTIES_ENABLE_STORAGE_CACHE,
storageProperties.get(PropertyAnalyzer.PROPERTIES_ENABLE_STORAGE_CACHE));
propsMap.put(PropertyAnalyzer.PROPERTIES_STORAGE_CACHE_TTL,
propsMap.put(PropertyAnalyzer.PROPERTIES_STORAGE_CACHE_TTL,
storageProperties.get(PropertyAnalyzer.PROPERTIES_STORAGE_CACHE_TTL));
propsMap.put(PropertyAnalyzer.PROPERTIES_ALLOW_ASYNC_WRITE_BACK,
propsMap.put(PropertyAnalyzer.PROPERTIES_ALLOW_ASYNC_WRITE_BACK,
storageProperties.get(PropertyAnalyzer.PROPERTIES_ALLOW_ASYNC_WRITE_BACK));
}

// storage type
propsMap.put(PropertyAnalyzer.PROPERTIES_STORAGE_FORMAT, olapTable.getStorageFormat().name());

// enable_persistent_index
propsMap.put(PropertyAnalyzer.PROPERTIES_ENABLE_PERSISTENT_INDEX, String.valueOf(olapTable.enablePersistentIndex()));

// compression type
if (olapTable.getCompressionType() == TCompressionType.LZ4_FRAME ||
if (olapTable.getCompressionType() == TCompressionType.LZ4_FRAME ||
olapTable.getCompressionType() == TCompressionType.LZ4) {
propsMap.put(PropertyAnalyzer.PROPERTIES_COMPRESSION, "LZ4");
} else {
Expand All @@ -211,7 +210,7 @@ private static Map<String, String> genProps(Table table) {
// storage media
Map<String, String> properties = olapTable.getTableProperty().getProperties();
if (properties.containsKey(PropertyAnalyzer.PROPERTIES_STORAGE_MEDIUM)) {
propsMap.put(PropertyAnalyzer.PROPERTIES_STORAGE_MEDIUM,
propsMap.put(PropertyAnalyzer.PROPERTIES_STORAGE_MEDIUM,
properties.get(PropertyAnalyzer.PROPERTIES_STORAGE_MEDIUM));
}
return propsMap;
Expand Down Expand Up @@ -249,12 +248,12 @@ private static TTableConfigInfo genNormalTableConfigInfo(Table table, TTableConf
}
String pkSb = Joiner.on(", ").join(keysColumnNames);
tableConfigInfo.setPrimary_key(olapTable.getKeysType().equals(KeysType.PRIMARY_KEYS)
|| olapTable.getKeysType().equals(KeysType.UNIQUE_KEYS) ? pkSb : DEFAULT_EMPTY_STRING);
|| olapTable.getKeysType().equals(KeysType.UNIQUE_KEYS) ? pkSb : DEFAULT_EMPTY_STRING);
tableConfigInfo.setPartition_key(partitionKeySb.toString());
tableConfigInfo.setDistribute_bucket(distributionInfo.getBucketNum());
tableConfigInfo.setDistribute_type("HASH");
tableConfigInfo.setDistribute_key(distributeKey);

// SORT KEYS
MaterializedIndexMeta index = olapTable.getIndexMetaByIndexId(olapTable.getBaseIndexId());
if (index.getSortKeyIdxes() == null) {
Expand All @@ -273,7 +272,6 @@ private static TTableConfigInfo genNormalTableConfigInfo(Table table, TTableConf

// tables
public static TGetTablesInfoResponse generateTablesInfoResponse(TGetTablesInfoRequest request) throws TException {

TGetTablesInfoResponse response = new TGetTablesInfoResponse();
List<TTableInfo> infos = new ArrayList<>();

Expand All @@ -282,16 +280,22 @@ public static TGetTablesInfoResponse generateTablesInfoResponse(TGetTablesInfoRe
for (String dbName : result.authorizedDbs) {
Database db = GlobalStateMgr.getCurrentState().getDb(dbName);
if (db != null) {
db.readLock();
try {
List<Table> allTables = db.getTables();
for (Table table : allTables) {
List<Table> allTables = db.getTables();
for (Table table : allTables) {

if (!GlobalStateMgr.getCurrentState().getAuth().checkTblPriv(result.currentUser, dbName,
table.getName(), PrivPredicate.SHOW)) {
if (!GlobalStateMgr.getCurrentState().getAuth().checkTblPriv(result.currentUser, dbName,
table.getName(), PrivPredicate.SHOW)) {
continue;
}

if (request.isSetTable_name()) {
if (!table.getName().equals(request.getTable_name())) {
continue;
}
}

db.readLock();
try {
TTableInfo info = new TTableInfo();

info.setTable_catalog(DEF);
Expand All @@ -314,7 +318,7 @@ public static TGetTablesInfoResponse generateTablesInfoResponse(TGetTablesInfoRe
info.setChecksum(DEFAULT_EMPTY_NUM);
info.setTable_comment(table.getComment());

if (table.isOlapOrLakeTable() ||
if (table.isOlapOrLakeTable() ||
table.getType() == TableType.OLAP_EXTERNAL ||
table.getType() == TableType.MATERIALIZED_VIEW) {
// OLAP (done)
Expand All @@ -331,18 +335,18 @@ public static TGetTablesInfoResponse generateTablesInfoResponse(TGetTablesInfoRe
}
// TODO(cjs): other table type (HIVE, MYSQL, ICEBERG, HUDI, JDBC, ELASTICSEARCH)
infos.add(info);
} finally {
db.readUnlock();
}
} finally {
db.readUnlock();
}
}
}
}
}
response.setTables_infos(infos);
return response;
}

public static TTableInfo genNormalTableInfo(Table table, TTableInfo info) {

OlapTable olapTable = (OlapTable) table;
Collection<Partition> partitions = table.getPartitions();
long lastUpdateTime = 0L;
Expand All @@ -359,7 +363,7 @@ public static TTableInfo genNormalTableInfo(Table table, TTableInfo info) {
info.setTable_rows(totalRowsOfTable);
// AVG_ROW_LENGTH
if (totalRowsOfTable == 0) {
info.setAvg_row_length(0L);
info.setAvg_row_length(0L);
} else {
info.setAvg_row_length(totalBytesOfTable / totalRowsOfTable);
}
Expand Down
1 change: 1 addition & 0 deletions gensrc/thrift/FrontendService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ struct TTableConfigInfo {

struct TGetTablesInfoRequest {
1: optional TAuthInfo auth_info
2: optional string table_name;
}

struct TGetTablesInfoResponse {
Expand Down

0 comments on commit 71d72ed

Please sign in to comment.