in iceberg-catalog-migrator/cli/src/main/java/org/apache/polaris/iceberg/catalog/migrator/cli/BaseRegisterCommand.java [97:190]
protected abstract CatalogMigrator catalogMigrator(
Catalog sourceCatalog, Catalog targetCatalog, boolean enableStackTrace);
protected abstract boolean canProceed(Catalog sourceCatalog);
protected abstract String operation();
protected abstract String operated();
protected abstract String operate();
@Override
public Integer call() {
Set<TableIdentifier> identifiers = Collections.emptySet();
String identifierRegEx = identifierOptions != null ? identifierOptions.identifiersRegEx : null;
if (identifierOptions != null) {
identifiers = identifierOptions.processIdentifiersInput();
}
checkAndWarnAboutIdentifiers(identifiers, identifierRegEx);
validateOutputDir();
Catalog sourceCatalog = null;
Catalog targetCatalog = null;
try {
sourceCatalog = sourceCatalogOptions.build();
consoleLog.info("Configured source catalog: {}", sourceCatalog.name());
targetCatalog = targetCatalogOptions.build();
consoleLog.info("Configured target catalog: {}", targetCatalog.name());
if (!isDryRun && !disablePrompts && !canProceed(sourceCatalog)) {
return 1;
}
CatalogMigrator catalogMigrator =
catalogMigrator(sourceCatalog, targetCatalog, enableStackTrace);
if (identifiers.isEmpty()) {
consoleLog.info("Identifying tables for {} ...", operation());
identifiers = catalogMigrator.getMatchingTableIdentifiers(identifierRegEx);
if (identifiers.isEmpty()) {
consoleLog.warn(
"No tables were identified for {}. Please check `catalog_migration.log` file for more info.",
operation());
return 1;
}
}
if (isDryRun) {
consoleLog.info("Dry run is completed.");
handleDryRunResult(identifiers);
return 0;
}
consoleLog.info("Identified {} tables for {}.", identifiers.size(), operation());
consoleLog.info("Started {} ...", operation());
CatalogMigrationResult result;
try {
int processedIdentifiersCount = 0;
for (TableIdentifier identifier : identifiers) {
catalogMigrator.registerTable(identifier);
processedIdentifiersCount++;
if (processedIdentifiersCount % BATCH_SIZE == 0
|| processedIdentifiersCount == identifiers.size()) {
consoleLog.info(
"Attempted {} for {} tables out of {} tables.",
operation(),
processedIdentifiersCount,
identifiers.size());
}
}
} finally {
consoleLog.info("Finished {} ...", operation());
result = catalogMigrator.result();
handleResults(result);
}
if (!result.failedToRegisterTableIdentifiers().isEmpty()
|| !result.failedToDeleteTableIdentifiers().isEmpty()
|| result.registeredTableIdentifiers().isEmpty()) {
return 1;
}
return 0;
} finally {
close(sourceCatalog);
close(targetCatalog);
}
}