Skip to content

Commit

Permalink
[AMORO-1870]: table filter apache#1870 \n * add table filter
Browse files Browse the repository at this point in the history
  • Loading branch information
刘政 committed Aug 23, 2023
1 parent 76da3c4 commit 8344546
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ conf/
*unit_test_base_tmp/

*/.gitignore
local/conf/
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class CatalogMetaProperties {
public static final String KEY_WAREHOUSE_DIR = "warehouse.dir";
public static final String KEY_WAREHOUSE = "warehouse";
public static final String KEY_DATABASE_FILTER_REGULAR_EXPRESSION = "database.filter-regular-expression";
public static final String KEY_TABLE_FILTER_REGULAR_EXPRESSION = "table.filter-regular-expression";

public static final String CATALOG_TYPE_HADOOP = "hadoop";
public static final String CATALOG_TYPE_HIVE = "hive";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class IcebergCatalogWrapper implements ArcticCatalog {
private CatalogMeta meta;
private Map<String, String> customProperties;
private Pattern databaseFilterPattern;
private Pattern tableFilterPattern;
private transient TableMetaStore tableMetaStore;
private transient Catalog icebergCatalog;

Expand Down Expand Up @@ -90,6 +91,15 @@ private void initialize(CatalogMeta meta, Map<String, String> properties) {
} else {
databaseFilterPattern = null;
}

if (meta.getCatalogProperties().containsKey(CatalogMetaProperties.KEY_TABLE_FILTER_REGULAR_EXPRESSION)) {
String tableFilter =
meta.getCatalogProperties().get(CatalogMetaProperties.KEY_TABLE_FILTER_REGULAR_EXPRESSION);
tableFilterPattern = Pattern.compile(tableFilter);
} else {
tableFilterPattern = null;
}

}

public IcebergCatalogWrapper(CatalogMeta meta, Map<String, String> properties) {
Expand Down Expand Up @@ -148,9 +158,10 @@ public void dropDatabase(String databaseName) {
@Override
public List<TableIdentifier> listTables(String database) {
return tableMetaStore.doAs(() -> icebergCatalog.listTables(Namespace.of(database)).stream()
.filter(tableIdentifier -> tableIdentifier.namespace().levels().length == 1)
.map(tableIdentifier -> TableIdentifier.of(name(), database, tableIdentifier.name()))
.collect(Collectors.toList()));
.filter(tableIdentifier -> tableIdentifier.namespace().levels().length == 1
&& (tableFilterPattern == null || tableFilterPattern.matcher(tableIdentifier.name()).matches()))
.map(tableIdentifier -> TableIdentifier.of(name(), database, tableIdentifier.name()))
.collect(Collectors.toList()));
}

public List<TableIdentifier> listTables() {
Expand Down

0 comments on commit 8344546

Please sign in to comment.