-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Destination Iceberg: integration test for glue #49467
Open
edgao
wants to merge
16
commits into
master
Choose a base branch
from
edgao/iceberg_glue_integration_test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+214
−138
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9a6881d
log exception correctly
edgao 7c6699e
start writing things
edgao 37c1062
add table id generator
edgao bdfd7ce
basic cleaner
edgao 77b4855
get correct catalog instance
edgao 5a540c8
coment
edgao d7d7f40
disable tests everywhere
edgao 5c073f9
handle concurrent nonsense
edgao a334188
add secret
edgao 50e3b2e
minor refactor
edgao 6107ab9
format
edgao ca12895
remove redundant constructor
edgao 16bf80f
also add to check test
edgao e4abf35
add to check test + reenable
edgao 6204548
version bump
edgao ea13d27
use table cleaner
edgao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
46 changes: 46 additions & 0 deletions
46
...erg-v2/src/main/kotlin/io/airbyte/integrations/destination/iceberg/v2/TableIdGenerator.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,46 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.iceberg.v2 | ||
|
||
import io.airbyte.cdk.load.command.DestinationStream | ||
import io.airbyte.cdk.load.command.iceberg.parquet.GlueCatalogConfiguration | ||
import io.micronaut.context.annotation.Factory | ||
import javax.inject.Singleton | ||
import org.apache.iceberg.catalog.Namespace | ||
import org.apache.iceberg.catalog.TableIdentifier | ||
|
||
/** | ||
* Convert our internal stream descriptor to an Iceberg [TableIdentifier]. Implementations should | ||
* handle catalog-specific naming restrictions. | ||
*/ | ||
// TODO accept default namespace in config as a val here | ||
interface TableIdGenerator { | ||
fun toTableIdentifier(stream: DestinationStream.Descriptor): TableIdentifier | ||
} | ||
|
||
class SimpleTableIdGenerator : TableIdGenerator { | ||
override fun toTableIdentifier(stream: DestinationStream.Descriptor): TableIdentifier = | ||
tableIdOf(stream.namespace!!, stream.name) | ||
} | ||
|
||
/** AWS Glue requires lowercase database+table names. */ | ||
class GlueTableIdGenerator : TableIdGenerator { | ||
override fun toTableIdentifier(stream: DestinationStream.Descriptor): TableIdentifier = | ||
tableIdOf(stream.namespace!!.lowercase(), stream.name.lowercase()) | ||
} | ||
|
||
@Factory | ||
class TableIdGeneratorFactory(private val icebergConfiguration: IcebergV2Configuration) { | ||
@Singleton | ||
fun create() = | ||
when (icebergConfiguration.icebergCatalogConfiguration.catalogConfiguration) { | ||
is GlueCatalogConfiguration -> GlueTableIdGenerator() | ||
else -> SimpleTableIdGenerator() | ||
} | ||
} | ||
|
||
// iceberg namespace+name must both be nonnull. | ||
private fun tableIdOf(namespace: String, name: String) = | ||
TableIdentifier.of(Namespace.of(namespace), name) |
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
35 changes: 35 additions & 0 deletions
35
...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,35 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.iceberg.v2 | ||
|
||
import io.airbyte.cdk.load.test.util.DestinationCleaner | ||
import io.airbyte.cdk.load.test.util.IntegrationTest.Companion.isNamespaceOld | ||
import io.airbyte.cdk.load.test.util.IntegrationTest.Companion.randomizedNamespaceRegex | ||
import io.airbyte.integrations.destination.iceberg.v2.io.IcebergTableCleaner | ||
import io.airbyte.integrations.destination.iceberg.v2.io.IcebergUtil | ||
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 { | ||
override fun cleanup() { | ||
val namespaces: List<Namespace> = | ||
(catalog as SupportsNamespaces).listNamespaces().filter { | ||
val namespace = it.level(0) | ||
randomizedNamespaceRegex.matches(namespace) && isNamespaceOld(namespace) | ||
} | ||
|
||
// we're passing explicit TableIdentifier to clearTable, so just use SimpleTableIdGenerator | ||
val tableCleaner = IcebergTableCleaner(IcebergUtil(SimpleTableIdGenerator())) | ||
|
||
namespaces.forEach { namespace -> | ||
catalog.listTables(namespace).forEach { tableId -> | ||
val table = catalog.loadTable(tableId) | ||
tableCleaner.clearTable(catalog, tableId, table.io(), table.location()) | ||
} | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have IcebergTableCleaner which has the
clearTable
method, we should use thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you remember why that method has an explicit
io.deletePrefix
call? afaict,glueCatalog.dropTable(..., purge = true)
is sufficient to delete the underlying files from S3(maybe the nessie catalog behaves differently?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdpgrailsdev would know it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edgao Nessie doesn't delete the data when the drop table API is called. This method was added to also cleanup the stored data files associated the table when we drop it via the API call. This may or may not be necessary for all catalogs, so we should test what happens in Glue if we just call the API method on the catalog to delete the table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nessie why :(
(done in ea13d27)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed that glue does the right thing if you set the
purge
flag to true, but... it's easy enough to call the table cleaner always