diff --git a/be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp b/be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp index fd7c10b4ea6d6..cd389b9f0fee2 100644 --- a/be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp +++ b/be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp @@ -62,6 +62,10 @@ Status SchemaTablesScanner::start(RuntimeState* state) { TGetTablesInfoRequest get_tables_info_request; get_tables_info_request.__set_auth_info(auth_info); + if (nullptr != _param->table) { + get_tables_info_request.__set_table_name(*(_param->table)); + } + 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)); diff --git a/fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java b/fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java index d483e2f0f53d1..0589a796a73cf 100644 --- a/fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java +++ b/fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java @@ -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"; @@ -106,7 +106,7 @@ public AuthDbRequestResult(List authorizedDbs, UserIdentity currentUser) // tables_config public static TGetTablesConfigResponse generateTablesConfigResponse(TGetTablesConfigRequest request) throws TException { - + TGetTablesConfigResponse resp = new TGetTablesConfigResponse(); List tList = new ArrayList<>(); @@ -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) @@ -143,14 +143,13 @@ public static TGetTablesConfigResponse generateTablesConfigResponse(TGetTablesCo } } finally { db.readUnlock(); - } - } + } + } } resp.tables_config_infos = tList; return resp; } - private static Map genProps(Table table) { if (table.getType() == TableType.MATERIALIZED_VIEW) { @@ -159,10 +158,10 @@ private static Map genProps(Table table) { } OlapTable olapTable = (OlapTable) table; - Map propsMap = new HashMap<>(); - + Map propsMap = new HashMap<>(); + propsMap.put(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM, String.valueOf(olapTable.getDefaultReplicationNum())); - + // bloom filter Set bfColumnNames = olapTable.getCopiedBfColumns(); if (bfColumnNames != null) { @@ -186,22 +185,22 @@ private static Map genProps(Table table) { // enable storage cache && cache ttl if (table.isLakeTable()) { Map 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 { @@ -211,7 +210,7 @@ private static Map genProps(Table table) { // storage media Map 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; @@ -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) { @@ -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 infos = new ArrayList<>(); @@ -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 allTables = db.getTables(); - for (Table table : allTables) { + List
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); @@ -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) @@ -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 partitions = table.getPartitions(); long lastUpdateTime = 0L; @@ -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); } diff --git a/gensrc/thrift/FrontendService.thrift b/gensrc/thrift/FrontendService.thrift index 27427fbfad3ee..89331a9435cd3 100644 --- a/gensrc/thrift/FrontendService.thrift +++ b/gensrc/thrift/FrontendService.thrift @@ -1082,6 +1082,7 @@ struct TTableConfigInfo { struct TGetTablesInfoRequest { 1: optional TAuthInfo auth_info + 2: optional string table_name; } struct TGetTablesInfoResponse {