-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Add KeyToValue transform #170
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
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
25aaa9a
feat: Add KeyToValue transform
RyanSkraba e6b9ae7
doc: Minor README fixes
RyanSkraba d081c4b
fix: Beautify for checkstyle
RyanSkraba a86b4a6
test: Add KeyToValue integration test
RyanSkraba b9b295e
fix: Remove unnecessary configuration
RyanSkraba e966d30
fix: Rename methods for readability and use standard infer
RyanSkraba 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 hidden or 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 hidden or 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
88 changes: 88 additions & 0 deletions
88
src/integration-test/java/io/aiven/kafka/connect/transforms/TestKeyToValueConnector.java
This file contains hidden or 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,88 @@ | ||
/* | ||
* Copyright 2025 Aiven Oy | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.aiven.kafka.connect.transforms; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.kafka.connect.connector.Task; | ||
import org.apache.kafka.connect.data.Schema; | ||
import org.apache.kafka.connect.data.SchemaBuilder; | ||
import org.apache.kafka.connect.data.Struct; | ||
import org.apache.kafka.connect.source.SourceRecord; | ||
import org.apache.kafka.connect.source.SourceTask; | ||
|
||
public class TestKeyToValueConnector extends AbstractTestSourceConnector { | ||
|
||
static final long MESSAGES_TO_PRODUCE = 10L; | ||
|
||
static final String TARGET_TOPIC = "key-to-value-target-topic"; | ||
|
||
@Override | ||
public Class<? extends Task> taskClass() { | ||
return TestKeyToValueConnector.TestSourceConnectorTask.class; | ||
} | ||
|
||
public static class TestSourceConnectorTask extends SourceTask { | ||
private int counter = 0; | ||
|
||
private final Schema keySchema = SchemaBuilder.struct().field("a1", SchemaBuilder.STRING_SCHEMA) | ||
.field("a2", SchemaBuilder.STRING_SCHEMA) | ||
.field("a3", SchemaBuilder.STRING_SCHEMA).schema(); | ||
private final Struct key = new Struct(keySchema).put("a1", "a1").put("a2", "a2").put("a3", "a3"); | ||
private final Schema valueSchema = SchemaBuilder.struct().field("b1", SchemaBuilder.STRING_SCHEMA) | ||
.field("b2", SchemaBuilder.STRING_SCHEMA) | ||
.field("b3", SchemaBuilder.STRING_SCHEMA).schema(); | ||
private final Struct value = new Struct(valueSchema).put("b1", "b1").put("b2", "b2").put("b3", "b3"); | ||
|
||
@Override | ||
public void start(final Map<String, String> props) { | ||
} | ||
|
||
@Override | ||
public List<SourceRecord> poll() { | ||
if (counter >= MESSAGES_TO_PRODUCE) { | ||
return null; // indicate pause | ||
} | ||
|
||
final Map<String, String> sourcePartition = new HashMap<>(); | ||
sourcePartition.put("partition", "0"); | ||
final Map<String, String> sourceOffset = new HashMap<>(); | ||
sourceOffset.put("offset", Integer.toString(counter)); | ||
|
||
counter += 1; | ||
|
||
return Collections.singletonList( | ||
new SourceRecord(sourcePartition, sourceOffset, | ||
TARGET_TOPIC, | ||
keySchema, key, | ||
valueSchema, value) | ||
); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
} | ||
|
||
@Override | ||
public String version() { | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
Shouldn't this be KeyToValueConnectorTest rather than TestKeyToValueConnector?
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.
Ugh, this isn't a test :/
It needs a better name, or even optimised with a better strategy for all integration tests... Do you have any suggestions for the name for now?
MockKeyToValueSource
isn't quite right either :/