forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor debezium harness in CDK, push connector-specific logic down …
…to connectors (airbytehq#34573)
- Loading branch information
1 parent
7501097
commit 8ce33c2
Showing
109 changed files
with
666 additions
and
739 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
2 changes: 1 addition & 1 deletion
2
airbyte-cdk/java/airbyte-cdk/core/src/main/resources/version.properties
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 |
---|---|---|
@@ -1 +1 @@ | ||
version=0.15.2 | ||
version=0.16.0 |
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
66 changes: 66 additions & 0 deletions
66
.../src/main/java/io/airbyte/cdk/integrations/debezium/internals/DebeziumEventConverter.java
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,66 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.integrations.debezium.internals; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import io.airbyte.cdk.integrations.debezium.CdcMetadataInjector; | ||
import io.airbyte.protocol.models.v0.AirbyteMessage; | ||
import io.airbyte.protocol.models.v0.AirbyteRecordMessage; | ||
import java.time.Instant; | ||
|
||
public interface DebeziumEventConverter { | ||
|
||
String CDC_LSN = "_ab_cdc_lsn"; | ||
String CDC_UPDATED_AT = "_ab_cdc_updated_at"; | ||
String CDC_DELETED_AT = "_ab_cdc_deleted_at"; | ||
String AFTER_EVENT = "after"; | ||
String BEFORE_EVENT = "before"; | ||
String OPERATION_FIELD = "op"; | ||
String SOURCE_EVENT = "source"; | ||
|
||
static AirbyteMessage buildAirbyteMessage( | ||
final JsonNode source, | ||
final CdcMetadataInjector cdcMetadataInjector, | ||
final Instant emittedAt, | ||
final JsonNode data) { | ||
final String streamNamespace = cdcMetadataInjector.namespace(source); | ||
final String streamName = cdcMetadataInjector.name(source); | ||
|
||
final AirbyteRecordMessage airbyteRecordMessage = new AirbyteRecordMessage() | ||
.withStream(streamName) | ||
.withNamespace(streamNamespace) | ||
.withEmittedAt(emittedAt.toEpochMilli()) | ||
.withData(data); | ||
|
||
return new AirbyteMessage() | ||
.withType(AirbyteMessage.Type.RECORD) | ||
.withRecord(airbyteRecordMessage); | ||
} | ||
|
||
static JsonNode addCdcMetadata( | ||
final ObjectNode baseNode, | ||
final JsonNode source, | ||
final CdcMetadataInjector cdcMetadataInjector, | ||
final boolean isDelete) { | ||
|
||
final long transactionMillis = source.get("ts_ms").asLong(); | ||
final String transactionTimestamp = Instant.ofEpochMilli(transactionMillis).toString(); | ||
|
||
baseNode.put(CDC_UPDATED_AT, transactionTimestamp); | ||
cdcMetadataInjector.addMetaData(baseNode, source); | ||
|
||
if (isDelete) { | ||
baseNode.put(CDC_DELETED_AT, transactionTimestamp); | ||
} else { | ||
baseNode.put(CDC_DELETED_AT, (String) null); | ||
} | ||
|
||
return baseNode; | ||
} | ||
|
||
AirbyteMessage toAirbyteMessage(final ChangeEventWithMetadata event); | ||
|
||
} |
Oops, something went wrong.