Skip to content

bulk-cdk: DiscoverOperation supports isResumable #43406

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

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion airbyte-cdk/bulk/core/base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
api 'com.fasterxml.jackson.core:jackson-databind'
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
api 'com.kjetland:mbknor-jackson-jsonschema_2.13:1.0.39'
api('io.airbyte.airbyte-protocol:protocol-models:0.9.0') {
api('io.airbyte.airbyte-protocol:protocol-models:0.12.2') {
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'com.google.api-client'
exclude group: 'org.apache.logging.log4j'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ class DiscoverOperation(
}
continue
}
val primaryKeys: List<List<String>> =
metadataQuerier.primaryKeys(name, namespace)
val discoveredStream = DiscoveredStream(name, namespace, fields, primaryKeys)
val primaryKey: List<List<String>> = metadataQuerier.primaryKey(name, namespace)
val discoveredStream = DiscoveredStream(name, namespace, fields, primaryKey)
airbyteStreams.add(toAirbyteStream(discoveredStream))
}
}
Expand All @@ -68,6 +67,7 @@ class DiscoverOperation(
airbyteStream.withSourceDefinedPrimaryKey(
if (isValidPK) discoveredStream.primaryKeyColumnIDs else listOf(),
)
airbyteStream.isResumable = airbyteStream.sourceDefinedPrimaryKey.isNotEmpty()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pleasantly concise change!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not one that will age particularly well; but I prefer to punt rather than anticipating future needs. Conceivably, a stream may not have a PK and yet still be resumable, and vice-versa.

if (config.global) {
// There is a global feed of incremental records, like CDC.
airbyteStreamDecorator.decorateGlobal(airbyteStream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface AirbyteStreamDecorator {
* message.
*
* This method does not determine (1), of course, because the source keys are defined in the
* source database itself and are retrieved via [MetadataQuerier.primaryKeys]. Instead, this
* source database itself and are retrieved via [MetadataQuerier.primaryKey]. Instead, this
* method determines (2) based on the type information of the field, typically the [FieldType]
* objects. For instance if the [Field.type] does not map to a [LosslessFieldType] then the
* field can't reliably round-trip checkpoint values during a resumable initial sync.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ interface MetadataQuerier : AutoCloseable {
streamNamespace: String?,
): List<Field>

/** Queries the information_schema for all primary keys for the given table. */
fun primaryKeys(
/** Queries the information_schema for any primary key on the given table. */
fun primaryKey(
streamName: String,
streamNamespace: String?,
): List<List<String>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class JdbcMetadataQuerierTest {
val tableName = (mdq as JdbcMetadataQuerier).findTableName("KV", "PUBLIC")
Assertions.assertNotNull(tableName)
Assertions.assertEquals(expectedColumnMetadata, mdq.columnMetadata(tableName!!))
Assertions.assertEquals(listOf(listOf("K")), mdq.primaryKeys("KV", "PUBLIC"))
Assertions.assertEquals(listOf(listOf("K")), mdq.primaryKey("KV", "PUBLIC"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ResourceDrivenMetadataQuerierFactory(
?: throw SQLException("query failed", "tbl")
}

override fun primaryKeys(
override fun primaryKey(
streamName: String,
streamNamespace: String?,
): List<List<String>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class JdbcMetadataQuerier(

val memoizedPrimaryKeys = mutableMapOf<TableName, List<List<String>>>()

override fun primaryKeys(
override fun primaryKey(
streamName: String,
streamNamespace: String?,
): List<List<String>> {
Expand Down
Loading