-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bulk Load CDK: Preparatory Refactor for adding Force Flush (#46369)
- Loading branch information
1 parent
4fc3dbc
commit 679a5c4
Showing
6 changed files
with
127 additions
and
56 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
34 changes: 34 additions & 0 deletions
34
airbyte-cdk/bulk/core/load/src/main/kotlin/io/airbyte/cdk/state/FlushStrategy.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,34 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.state | ||
|
||
import com.google.common.collect.Range | ||
import io.airbyte.cdk.command.DestinationConfiguration | ||
import io.airbyte.cdk.command.DestinationStream | ||
import io.micronaut.context.annotation.Secondary | ||
import jakarta.inject.Singleton | ||
|
||
interface FlushStrategy { | ||
suspend fun shouldFlush( | ||
stream: DestinationStream, | ||
rangeRead: Range<Long>, | ||
bytesProcessed: Long | ||
): Boolean | ||
} | ||
|
||
@Singleton | ||
@Secondary | ||
class DefaultFlushStrategy( | ||
private val config: DestinationConfiguration, | ||
) : FlushStrategy { | ||
|
||
override suspend fun shouldFlush( | ||
stream: DestinationStream, | ||
rangeRead: Range<Long>, | ||
bytesProcessed: Long | ||
): Boolean { | ||
return bytesProcessed >= config.recordBatchSizeBytes | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
airbyte-cdk/bulk/core/load/src/main/kotlin/io/airbyte/cdk/util/CoroutineUtils.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,13 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.util | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.transformWhile | ||
|
||
fun <T> Flow<T>.takeUntilInclusive(predicate: (T) -> Boolean): Flow<T> = transformWhile { value -> | ||
emit(value) | ||
!predicate(value) | ||
} |
18 changes: 18 additions & 0 deletions
18
airbyte-cdk/bulk/core/load/src/main/kotlin/io/airbyte/cdk/util/RangeUtils.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,18 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.util | ||
|
||
import com.google.common.collect.Range | ||
|
||
// Necessary because Guava's Range/sets have no "empty" range | ||
fun Range<Long>?.withNextAdjacentValue(index: Long): Range<Long> { | ||
return if (this == null) { | ||
Range.singleton(index) | ||
} else if (index != this.upperEndpoint() + 1L) { | ||
throw IllegalStateException("Expected index ${this.upperEndpoint() + 1}, got $index") | ||
} else { | ||
this.span(Range.singleton(index)) | ||
} | ||
} |
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