-
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.
[source volcano] Decorate stream with cursor field for trigger based …
…CDC stream (#53152)
- Loading branch information
Showing
10 changed files
with
162 additions
and
59 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
8 changes: 3 additions & 5 deletions
8
...yte-cdk/bulk/core/extract/src/main/kotlin/io/airbyte/cdk/discover/AirbyteStreamFactory.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
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
57 changes: 31 additions & 26 deletions
57
...toolkits/extract-jdbc/src/main/kotlin/io/airbyte/cdk/discover/JdbcAirbyteStreamFactory.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
97 changes: 97 additions & 0 deletions
97
...kits/extract-jdbc/src/test/kotlin/io/airbyte/cdk/discover/JdbcAirbyteStreamFactoryTest.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,97 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.discover | ||
|
||
import io.airbyte.cdk.StreamIdentifier | ||
import io.airbyte.cdk.command.SourceConfiguration | ||
import io.airbyte.cdk.h2source.H2SourceOperations | ||
import io.airbyte.cdk.jdbc.BigIntegerFieldType | ||
import io.airbyte.cdk.jdbc.BooleanFieldType | ||
import io.airbyte.cdk.jdbc.StringFieldType | ||
import io.airbyte.protocol.models.v0.SyncMode | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.`when` | ||
|
||
class JdbcAirbyteStreamFactoryTest { | ||
|
||
private lateinit var config: SourceConfiguration | ||
private lateinit var streamId: StreamIdentifier | ||
private lateinit var discoveredStream: DiscoveredStream | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
config = mock(SourceConfiguration::class.java) | ||
streamId = mock(StreamIdentifier::class.java) | ||
discoveredStream = mock(DiscoveredStream::class.java) | ||
`when`(streamId.name).thenReturn("test_stream") | ||
`when`(streamId.namespace).thenReturn("test_namespace") | ||
`when`(discoveredStream.id).thenReturn(streamId) | ||
`when`(discoveredStream.columns) | ||
.thenReturn(listOf(Field("id", BigIntegerFieldType), Field("name", StringFieldType))) | ||
} | ||
|
||
@Test | ||
fun testCreate_withCdcAndWithPK() { | ||
`when`(config.isCdc()).thenReturn(true) | ||
`when`(discoveredStream.primaryKeyColumnIDs).thenReturn(listOf(listOf("id"))) | ||
|
||
val factory = H2SourceOperations() | ||
val stream = factory.create(config, discoveredStream) | ||
|
||
Assertions.assertEquals( | ||
listOf(SyncMode.FULL_REFRESH, SyncMode.INCREMENTAL), | ||
stream.supportedSyncModes | ||
) | ||
Assertions.assertTrue(stream.sourceDefinedCursor) | ||
Assertions.assertTrue(stream.isResumable) | ||
} | ||
|
||
@Test | ||
fun testCreate_withCdcAndWithoutPK() { | ||
`when`(config.isCdc()).thenReturn(true) | ||
`when`(discoveredStream.primaryKeyColumnIDs).thenReturn(emptyList()) | ||
|
||
val factory = H2SourceOperations() | ||
val stream = factory.create(config, discoveredStream) | ||
|
||
Assertions.assertEquals(listOf(SyncMode.FULL_REFRESH), stream.supportedSyncModes) | ||
Assertions.assertFalse(stream.sourceDefinedCursor) | ||
Assertions.assertFalse(stream.isResumable) | ||
} | ||
|
||
@Test | ||
fun testCreate_withNonCdcAndWithPK() { | ||
`when`(config.isCdc()).thenReturn(false) | ||
`when`(discoveredStream.primaryKeyColumnIDs).thenReturn(listOf(listOf("id"))) | ||
|
||
val factory = H2SourceOperations() | ||
val stream = factory.create(config, discoveredStream) | ||
|
||
Assertions.assertEquals( | ||
listOf(SyncMode.FULL_REFRESH, SyncMode.INCREMENTAL), | ||
stream.supportedSyncModes | ||
) | ||
Assertions.assertFalse(stream.sourceDefinedCursor) | ||
Assertions.assertTrue(stream.isResumable) | ||
} | ||
|
||
@Test | ||
fun testCreate_withNonCdcAndWithoutPK() { | ||
`when`(config.isCdc()).thenReturn(false) | ||
`when`(discoveredStream.primaryKeyColumnIDs).thenReturn(emptyList()) | ||
`when`(discoveredStream.columns) | ||
.thenReturn(listOf(Field("non_cursor_col", BooleanFieldType))) | ||
|
||
val factory = H2SourceOperations() | ||
val stream = factory.create(config, discoveredStream) | ||
|
||
Assertions.assertEquals(listOf(SyncMode.FULL_REFRESH), stream.supportedSyncModes) | ||
Assertions.assertFalse(stream.sourceDefinedCursor) | ||
Assertions.assertFalse(stream.isResumable) | ||
} | ||
} |
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