public Set getMatchingTableIdentifiers()

in iceberg-catalog-migrator/api/src/main/java/org/apache/polaris/iceberg/catalog/migrator/api/CatalogMigrator.java [97:135]


  public Set<TableIdentifier> getMatchingTableIdentifiers(String identifierRegex) {
    LOG.info("Collecting all the namespaces from source catalog...");
    Set<Namespace> namespaces = new LinkedHashSet<>();
    getAllNamespacesFromSourceCatalog(Namespace.empty(), namespaces);

    Predicate<TableIdentifier> matchedIdentifiersPredicate;
    if (identifierRegex == null) {
      LOG.info("Collecting all the tables from all the namespaces of source catalog...");
      matchedIdentifiersPredicate = tableIdentifier -> true;
    } else {
      LOG.info(
          "Collecting all the tables from all the namespaces of source catalog"
              + " which matches the regex pattern:{}",
          identifierRegex);
      Pattern pattern = Pattern.compile(identifierRegex);
      matchedIdentifiersPredicate =
          tableIdentifier -> pattern.matcher(tableIdentifier.toString()).matches();
    }
    return namespaces.stream()
        .flatMap(
            namespace -> {
              try {
                return sourceCatalog().listTables(namespace).stream()
                    .filter(matchedIdentifiersPredicate);
              } catch (IllegalArgumentException | NoSuchNamespaceException exception) {
                if (namespace.isEmpty()) {
                  // some catalogs don't support empty namespace.
                  // Hence, just log the warning and ignore the exception.
                  LOG.warn(
                      "Failed to identify tables from empty namespace : {}",
                      exception.getMessage());
                  return Stream.empty();
                } else {
                  throw exception;
                }
              }
            })
        .collect(Collectors.toCollection(LinkedHashSet::new));
  }