From bb583c274e584a1d839522f9b0feac8ed5d78e9f Mon Sep 17 00:00:00 2001 From: Wang Tao Date: Thu, 25 Aug 2022 21:34:24 +0800 Subject: [PATCH] [ARCTIC-115][ams] support filter database or table by keywords (#131) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【ams】support filter database or table by keywords #115 --- .../ams/server/controller/TableController.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ams/ams-server/src/main/java/com/netease/arctic/ams/server/controller/TableController.java b/ams/ams-server/src/main/java/com/netease/arctic/ams/server/controller/TableController.java index a382feffac..a6c8b3d5a5 100644 --- a/ams/ams-server/src/main/java/com/netease/arctic/ams/server/controller/TableController.java +++ b/ams/ams-server/src/main/java/com/netease/arctic/ams/server/controller/TableController.java @@ -54,6 +54,7 @@ import com.netease.arctic.table.TableIdentifier; import io.javalin.http.Context; import io.javalin.http.HttpCode; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -344,12 +345,15 @@ public static void getTableOperations(Context ctx) { public static void getTableList(Context ctx) { String catalog = ctx.pathParam("catalog"); String db = ctx.pathParam("db"); + String keywords = ctx.queryParam("keywords"); String thriftHost = ArcticMetaStore.conf.getString(ArcticMetaStoreConf.THRIFT_BIND_HOST); Integer thriftPort = ArcticMetaStore.conf.getInteger(ArcticMetaStoreConf.THRIFT_BIND_PORT); ArcticCatalog ac = CatalogUtil.getArcticCatalog(thriftHost, thriftPort, catalog); List tableIdentifiers = ac.listTables(db); - List tables = tableIdentifiers.stream().map(TableIdentifier::getTableName).collect(Collectors.toList()); + List tables = tableIdentifiers.stream().map(TableIdentifier::getTableName) + .filter(item -> StringUtils.isEmpty(keywords) || item.contains(keywords)) + .collect(Collectors.toList()); ctx.json(OkResponse.of(tables)); } @@ -360,11 +364,15 @@ public static void getTableList(Context ctx) { */ public static void getDatabaseList(Context ctx) { String catalog = ctx.pathParam("catalog"); + String keywords = ctx.queryParam("keywords"); String thriftHost = ArcticMetaStore.conf.getString(ArcticMetaStoreConf.THRIFT_BIND_HOST); Integer thriftPort = ArcticMetaStore.conf.getInteger(ArcticMetaStoreConf.THRIFT_BIND_PORT); ArcticCatalog ac = CatalogUtil.getArcticCatalog(thriftHost, thriftPort, catalog); - ctx.json(OkResponse.of(ac.listDatabases())); + List dbList = ac.listDatabases().stream() + .filter(item -> StringUtils.isEmpty(keywords) || item.contains(keywords)) + .collect(Collectors.toList()); + ctx.json(OkResponse.of(dbList)); } /**