@@ -8,61 +8,35 @@ import io.airbyte.cdk.command.DestinationStream
8
8
import io.airbyte.cdk.message.Batch
9
9
import io.airbyte.cdk.message.DestinationRecord
10
10
import io.airbyte.cdk.message.SimpleBatch
11
- import io.github.oshai.kotlinlogging.KotlinLogging
12
- import io.micronaut.context.annotation.Secondary
13
- import jakarta.inject.Singleton
14
11
15
12
/* *
16
13
* Implementor interface. The framework calls open and close once per stream at the beginning and
17
14
* end of processing. The framework calls processRecords once per batch of records as batches of the
18
15
* configured size become available. (Specified in @
19
- * [io.airbyte.cdk.command.WriteConfiguration.recordBatchSizeBytes]
16
+ * [io.airbyte.cdk.command.WriteConfiguration.recordBatchSizeBytes])
20
17
*
21
- * processBatch is called once per incomplete batch returned by either processRecords or
22
- * processBatch itself. See @[io.airbyte.cdk.message.Batch] for more details.
18
+ * [start] is called once before any records are processed.
19
+ *
20
+ * [processRecords] is called whenever a batch of records is available for processing, and only
21
+ * after [start] has returned successfully. The return value is a client-defined implementation of @
22
+ * [Batch] that the framework may pass to [processBatch] and/or [finalize]. (See @[Batch] for more
23
+ * details.)
24
+ *
25
+ * [processBatch] is called once per incomplete batch returned by either [processRecords] or
26
+ * [processBatch] itself.
27
+ *
28
+ * [finalize] is called once after all records and batches have been processed successfully.
29
+ *
30
+ * [close] is called once after all records have been processed, regardless of success or failure.
31
+ * If there are failed batches, they are passed in as an argument.
23
32
*/
24
33
interface StreamLoader {
25
34
val stream: DestinationStream
26
35
27
- suspend fun open () {}
36
+ suspend fun start () {}
28
37
suspend fun processRecords (records : Iterator <DestinationRecord >, totalSizeBytes : Long ): Batch
29
- suspend fun processBatch (batch : Batch ): Batch = SimpleBatch (state = Batch .State .COMPLETE )
30
- suspend fun close () {}
31
- }
32
-
33
- /* *
34
- * Default stream loader (Not yet implemented) will process the records into a locally staged file
35
- * of a format specified in the configuration.
36
- */
37
- class DefaultStreamLoader (
38
- override val stream : DestinationStream ,
39
- ) : StreamLoader {
40
- val log = KotlinLogging .logger {}
41
-
42
- override suspend fun processRecords (
43
- records : Iterator <DestinationRecord >,
44
- totalSizeBytes : Long
45
- ): Batch {
46
- TODO (
47
- " Default implementation adds airbyte metadata, maybe flattens, no-op maps, and converts to destination format"
48
- )
49
- }
50
- }
51
-
52
- /* *
53
- * If you do not need to perform initialization and teardown across all streams, or if your
54
- * per-stream operations do not need shared global state, implement this interface instead of @
55
- * [Destination]. The framework will call it exactly once per stream to create instances that will
56
- * be used for the life cycle of the stream.
57
- */
58
- interface StreamLoaderFactory {
59
- fun make (stream : DestinationStream ): StreamLoader
60
- }
38
+ suspend fun processBatch (batch : Batch ): Batch = SimpleBatch (Batch .State .COMPLETE )
39
+ suspend fun finalize () {}
61
40
62
- @Singleton
63
- @Secondary
64
- class DefaultStreamLoaderFactory () : StreamLoaderFactory {
65
- override fun make (stream : DestinationStream ): StreamLoader {
66
- TODO (" See above" )
67
- }
41
+ suspend fun close (failedBatches : List <Batch > = emptyList()) {}
68
42
}
0 commit comments