-
Notifications
You must be signed in to change notification settings - Fork 4
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
[DMS-322] Convert Debezium __deleted flagged record to tombstone #6
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
07d5425
[DMS-322] first cut
bradbanister c7efd33
fix complaints
bradbanister e77e1c6
fix complaints
bradbanister 9388088
Map instead of Struct
bradbanister c4fcb09
doc update
bradbanister 1a28ecb
fix checkstyle
bradbanister 4802736
not yet, but closer
bradbanister 150c172
working
bradbanister 2640a5b
remove debug statements
bradbanister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
71 changes: 71 additions & 0 deletions
71
...ransforms/src/main/java/org/edfi/kafka/connect/transforms/DebeziumDeletedToTombstone.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,71 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
package org.edfi.kafka.connect.transforms; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.connect.connector.ConnectRecord; | ||
import org.apache.kafka.connect.errors.DataException; | ||
import org.apache.kafka.connect.transforms.Transformation; | ||
|
||
public class DebeziumDeletedToTombstone<R extends ConnectRecord<R>> implements Transformation<R> { | ||
|
||
// Empty SMT configuration | ||
public static final ConfigDef CONFIG_DEF = new ConfigDef(); | ||
|
||
public static final String DELETED_FIELD = "__deleted"; | ||
|
||
@Override | ||
public ConfigDef config() { | ||
// No configuration needed | ||
return CONFIG_DEF; | ||
} | ||
|
||
// No configuration needed | ||
@Override | ||
public void configure(final Map<String, ?> settings) { | ||
} | ||
|
||
// If __deleted=true, nulls out the record value. | ||
@Override | ||
public R apply(final R record) { | ||
|
||
// Ignore tombstone records | ||
if (record.value() == null) { | ||
return null; | ||
} | ||
|
||
if (!(record.value() instanceof Map)) { | ||
throw new DataException("Value type must be castable to Map: " + record.toString()); | ||
} | ||
|
||
boolean isDeleted = false; | ||
try { | ||
@SuppressWarnings("unchecked") | ||
final Map<String, Object> recordValueAsMap = (Map<String, Object>) record.value(); | ||
final String isDeletedString = (String) recordValueAsMap.get(DELETED_FIELD); | ||
isDeleted = Boolean.valueOf(isDeletedString); | ||
} catch (final Exception e) { | ||
throw new DataException( | ||
"Value type must have __deleted as String: " + record.toString() + " " + e.toString()); | ||
} | ||
|
||
return record.newRecord( | ||
record.topic(), | ||
record.kafkaPartition(), | ||
record.keySchema(), | ||
record.key(), | ||
isDeleted ? null : record.valueSchema(), | ||
isDeleted ? null : record.value(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nulling out record value makes it a tombstone |
||
record.timestamp(), | ||
record.headers()); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...-fi-kafka-connect-transforms/src/main/java/org/edfi/kafka/connect/transforms/Utility.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,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
package org.edfi.kafka.connect.transforms; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.apache.kafka.connect.errors.DataException; | ||
|
||
public class Utility { | ||
// Returns string field with the given field name | ||
public static String getStringField(final String fieldName, final Map<String, Object> recordValues) { | ||
final Optional<String> result = Optional.ofNullable(recordValues.get(fieldName)) | ||
.map(field -> { | ||
if (!field.getClass().equals(String.class)) { | ||
throw new DataException(fieldName + " must be a string in record: " + recordValues.toString()); | ||
} | ||
return field; | ||
}) | ||
.map(Object::toString); | ||
|
||
if (result.isPresent() && !result.get().isBlank()) { | ||
return result.get(); | ||
} else { | ||
throw new DataException(fieldName + " in value can't be null or empty"); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files have different license headers now