Skip to content
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

chore: use the generation id implementation #48579

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import io.airbyte.cdk.load.message.Batch
import io.airbyte.cdk.load.message.DestinationFile
import io.airbyte.cdk.load.message.DestinationRecord
import io.airbyte.cdk.load.message.SimpleBatch
import io.airbyte.cdk.load.state.StreamIncompleteResult
import io.airbyte.cdk.load.write.StreamLoader
import io.airbyte.integrations.destination.iceberg.v2.io.IcebergTableCleaner
import io.airbyte.integrations.destination.iceberg.v2.io.IcebergTableWriterFactory
import io.airbyte.integrations.destination.iceberg.v2.io.IcebergUtil
import io.airbyte.integrations.destination.iceberg.v2.io.IcebergUtil.constructGenerationIdSuffix
Expand Down Expand Up @@ -68,10 +70,18 @@ class IcebergStreamLoader(
throw NotImplementedError("Destination Iceberg does not support universal file transfer.")
}

override suspend fun processBatch(batch: Batch): Batch {
log.info { "Moving staged object from $stagingBranchName to $mainBranchName" }
table.manageSnapshots().fastForwardBranch(mainBranchName, stagingBranchName).commit()

return SimpleBatch(Batch.State.COMPLETE)
override suspend fun close(streamFailure: StreamIncompleteResult?) {
if (streamFailure == null) {
table.manageSnapshots().fastForwardBranch(mainBranchName, stagingBranchName).commit()
if (stream.minimumGenerationId > 0) {
val icebergTableCleaner = IcebergTableCleaner()
for (i in 0 until stream.minimumGenerationId) {
icebergTableCleaner.deleteGenerationId(
table,
constructGenerationIdSuffix(i),
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ object IcebergUtil {
}

fun constructGenerationIdSuffix(stream: DestinationStream): String {
if (stream.generationId < 0) {
return constructGenerationIdSuffix(stream.generationId)
}

fun constructGenerationIdSuffix(generationId: Long): String {
if (generationId < 0) {
throw IllegalArgumentException(
"GenerationId must be non-negative. Provided: ${stream.generationId}",
"GenerationId must be non-negative. Provided: ${generationId}",
)
}
return "ab-generation-id-${stream.generationId}"
return "ab-generation-id-${generationId}"
}
/**
* Builds an Iceberg [Catalog].
Expand Down
Loading