Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] Add database filter to Server ExternalCatalog #2414

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public class CatalogMetaProperties {
// Deprecated from version v0.4.0, use KEY_WAREHOUSE
@Deprecated public static final String KEY_WAREHOUSE_DIR = "warehouse.dir";
public static final String KEY_WAREHOUSE = "warehouse";
/**
* @deprecated since 0.6.0, will be removed in 0.7.0; use {@link
* CatalogMetaProperties#KEY_TABLE_FILTER} instead.
*/
@Deprecated

zhoujinsong marked this conversation as resolved.
Show resolved Hide resolved
public static final String KEY_DATABASE_FILTER_REGULAR_EXPRESSION =
"database.filter-regular-expression";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
UnifiedCatalog unifiedCatalog;
TableMetaStore tableMetaStore;
private Pattern tableFilterPattern;
private Pattern databaseFilterPattern;

protected ExternalCatalog(CatalogMeta metadata) {
super(metadata);
Expand All @@ -32,6 +33,7 @@
this.tableMetaStore.doAs(
() -> new CommonUnifiedCatalog(this::getMetadata, Maps.newHashMap()));
updateTableFilter(metadata);
updateDatabaseFilter(metadata);
}

public void syncTable(String database, String tableName, TableFormat format) {
Expand All @@ -58,6 +60,7 @@
super.updateMetadata(metadata);
this.tableMetaStore = CatalogUtil.buildMetaStore(metadata);
this.unifiedCatalog.refresh();
updateDatabaseFilter(metadata);
updateTableFilter(metadata);
}

Expand All @@ -73,7 +76,14 @@

@Override
public List<String> listDatabases() {
return doAs(() -> unifiedCatalog.listDatabases());
return doAs(
() ->
unifiedCatalog.listDatabases().stream()
.filter(
database ->
databaseFilterPattern == null
|| databaseFilterPattern.matcher(database).matches())
.collect(Collectors.toList()));
}

@Override
Expand Down Expand Up @@ -109,6 +119,18 @@
return doAs(() -> unifiedCatalog.loadTable(database, tableName));
}

private void updateDatabaseFilter(CatalogMeta metadata) {
String databaseFilter =
metadata
.getCatalogProperties()
.get(CatalogMetaProperties.KEY_DATABASE_FILTER_REGULAR_EXPRESSION);
if (databaseFilter != null) {
databaseFilterPattern = Pattern.compile(databaseFilter);

Check warning on line 128 in ams/server/src/main/java/com/netease/arctic/server/catalog/ExternalCatalog.java

View check run for this annotation

Codecov / codecov/patch

ams/server/src/main/java/com/netease/arctic/server/catalog/ExternalCatalog.java#L128

Added line #L128 was not covered by tests
} else {
databaseFilterPattern = null;
}
}

private void updateTableFilter(CatalogMeta metadata) {
String tableFilter =
metadata.getCatalogProperties().get(CatalogMetaProperties.KEY_TABLE_FILTER);
Expand Down