-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[source-mysql-v2] add cdc initial read partition (#46901)
Co-authored-by: Rodi Reich Zilberman <867491+rodireich@users.noreply.github.com>
- Loading branch information
1 parent
4cf57cd
commit b22f250
Showing
8 changed files
with
326 additions
and
39 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
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
50 changes: 50 additions & 0 deletions
50
...src/main/kotlin/io/airbyte/integrations/source/mysql/MysqlCdcInitialSnapshotStateValue.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,50 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.source.mysql | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.databind.JsonNode | ||
import io.airbyte.cdk.command.OpaqueStateValue | ||
import io.airbyte.cdk.discover.Field | ||
import io.airbyte.cdk.read.Stream | ||
import io.airbyte.cdk.util.Jsons | ||
|
||
data class MysqlCdcInitialSnapshotStateValue( | ||
@JsonProperty("pk_val") val pkVal: String? = null, | ||
@JsonProperty("pk_name") val pkName: String? = null, | ||
@JsonProperty("version") val version: Int? = null, | ||
@JsonProperty("state_type") val stateType: String? = null, | ||
@JsonProperty("incremental_state") val incrementalState: JsonNode? = null, | ||
@JsonProperty("stream_name") val streamName: String? = null, | ||
@JsonProperty("cursor_field") val cursorField: List<String>? = null, | ||
@JsonProperty("stream_namespace") val streamNamespace: String? = null, | ||
) { | ||
companion object { | ||
/** Value representing the completion of a FULL_REFRESH snapshot. */ | ||
fun getSnapshotCompletedState(stream: Stream): OpaqueStateValue = | ||
Jsons.valueToTree( | ||
MysqlCdcInitialSnapshotStateValue( | ||
streamName = stream.name, | ||
cursorField = listOf(), | ||
streamNamespace = stream.namespace | ||
) | ||
) | ||
|
||
/** Value representing the progress of an ongoing snapshot. */ | ||
fun snapshotCheckpoint( | ||
primaryKey: List<Field>, | ||
primaryKeyCheckpoint: List<JsonNode>, | ||
): OpaqueStateValue { | ||
val primaryKeyField = primaryKey.first() | ||
return Jsons.valueToTree( | ||
MysqlCdcInitialSnapshotStateValue( | ||
pkName = primaryKeyField.id, | ||
pkVal = primaryKeyCheckpoint.first().asText(), | ||
stateType = "primary_key", | ||
) | ||
) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.