-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ration/kotlin/io/airbyte/integrations/destination/iceberg/v2/IcebergDestinationCleaner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.airbyte.integrations.destination.iceberg.v2 | ||
|
||
import io.airbyte.cdk.load.test.util.DestinationCleaner | ||
import io.airbyte.cdk.load.test.util.IntegrationTest.Companion.randomizedNamespaceDateFormatter | ||
import io.airbyte.cdk.load.test.util.IntegrationTest.Companion.randomizedNamespaceRegex | ||
import io.airbyte.integrations.destination.iceberg.v2.io.IcebergUtil | ||
import java.time.LocalDate | ||
import org.apache.iceberg.catalog.Catalog | ||
import org.apache.iceberg.catalog.Namespace | ||
import org.apache.iceberg.catalog.SupportsNamespaces | ||
|
||
class IcebergDestinationCleaner(private val catalog: Catalog) : DestinationCleaner { | ||
constructor(configuration: IcebergV2Configuration) : this( | ||
IcebergUtil(SimpleTableIdGenerator()).let { icebergUtil -> | ||
val props = icebergUtil.toCatalogProperties(configuration) | ||
icebergUtil.createCatalog(DEFAULT_CATALOG_NAME, props) | ||
} | ||
) | ||
|
||
override fun cleanup() { | ||
val cleanupCutoffDate = LocalDate.now().minusDays(15) | ||
val namespaces: List<Namespace> = | ||
(catalog as SupportsNamespaces) | ||
.listNamespaces() | ||
.filter { | ||
val matchResult = randomizedNamespaceRegex.find(it.level(0)) | ||
if (matchResult == null) { | ||
false | ||
} else { | ||
val namespaceCreationDate = LocalDate.parse( | ||
matchResult.groupValues[1], | ||
randomizedNamespaceDateFormatter | ||
) | ||
namespaceCreationDate.isBefore(cleanupCutoffDate) | ||
} | ||
} | ||
namespaces.forEach { namespace -> | ||
catalog.listTables(namespace) | ||
.forEach { table -> catalog.dropTable(table, /* purge = */ true) } | ||
catalog.dropNamespace(namespace) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters