Skip to content

Commit

Permalink
[ARCTIC-115][ams] support filter database or table by keywords (#131)
Browse files Browse the repository at this point in the history
【ams】support filter database or table by keywords #115
  • Loading branch information
Aireed committed Aug 25, 2022
1 parent 7aff61e commit bb583c2
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<TableIdentifier> tableIdentifiers = ac.listTables(db);
List<String> tables = tableIdentifiers.stream().map(TableIdentifier::getTableName).collect(Collectors.toList());
List<String> tables = tableIdentifiers.stream().map(TableIdentifier::getTableName)
.filter(item -> StringUtils.isEmpty(keywords) || item.contains(keywords))
.collect(Collectors.toList());
ctx.json(OkResponse.of(tables));
}

Expand All @@ -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<String> dbList = ac.listDatabases().stream()
.filter(item -> StringUtils.isEmpty(keywords) || item.contains(keywords))
.collect(Collectors.toList());
ctx.json(OkResponse.of(dbList));
}

/**
Expand Down

0 comments on commit bb583c2

Please sign in to comment.