-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9673: Filter and Conditional SMTs #8699
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 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
643e74e
KIP-585/KAFKA-9673: Filter and Conditional SMTs
tombentley 2cfe4e1
Use Predicates config group
tombentley 0f0e138
Some review comments
tombentley 6477fe9
fixup
tombentley 460c5f8
Comment
tombentley fba43c8
tidy and fix a couple of tests
tombentley f55e146
Numerous fixes and an integration test.
tombentley 49b362c
Review comments
tombentley e76a0b4
Review comments
tombentley 602a89d
Apply suggestions from code review
tombentley 03ce156
KAFKA-9673: Fix a few unit and integration tests
rhauch 60cd39e
KAFKA-9673: Added some tests, made others a bit more robust, and adde…
rhauch cbc8981
Trivial correction
tombentley 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
53 changes: 53 additions & 0 deletions
53
connect/api/src/main/java/org/apache/kafka/connect/transforms/predicates/Predicate.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,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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 org.apache.kafka.connect.transforms.predicates; | ||
|
|
||
| import org.apache.kafka.common.Configurable; | ||
| import org.apache.kafka.common.config.ConfigDef; | ||
| import org.apache.kafka.connect.connector.ConnectRecord; | ||
|
|
||
| /** | ||
| * <p>A predicate on records. | ||
| * Predicates can be used to conditionally apply a {@link org.apache.kafka.connect.transforms.Transformation} | ||
| * by configuring the transformation's {@code predicate} (and {@code negate}) configuration parameters. | ||
| * In particular, the {@code Filter} transformation can be conditionally applied in order to filter | ||
| * certain records from further processing. | ||
| * | ||
| * <p>Implementations of this interface must be public and have a public constructor with no parameters. | ||
| * | ||
| * @param <R> The type of record. | ||
| */ | ||
| public interface Predicate<R extends ConnectRecord<R>> extends Configurable, AutoCloseable { | ||
|
|
||
| /** | ||
| * Configuration specification for this predicate. | ||
| * | ||
| * @return the configuration definition for this predicate; never null | ||
| */ | ||
| ConfigDef config(); | ||
|
|
||
| /** | ||
| * Returns whether the given record satisfies this predicate. | ||
| * | ||
| * @param record the record to evaluate; may not be null | ||
| * @return true if the predicate matches, or false otherwise | ||
| */ | ||
|
tombentley marked this conversation as resolved.
|
||
| boolean test(R record); | ||
|
|
||
| @Override | ||
| void close(); | ||
| } | ||
375 changes: 269 additions & 106 deletions
375
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/ConnectorConfig.java
Large diffs are not rendered by default.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/PredicatedTransformation.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,81 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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 org.apache.kafka.connect.runtime; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.apache.kafka.common.config.ConfigDef; | ||
| import org.apache.kafka.common.utils.Utils; | ||
| import org.apache.kafka.connect.connector.ConnectRecord; | ||
| import org.apache.kafka.connect.errors.ConnectException; | ||
| import org.apache.kafka.connect.transforms.Transformation; | ||
| import org.apache.kafka.connect.transforms.predicates.Predicate; | ||
|
|
||
| /** | ||
| * Decorator for a {@link Transformation} which applies the delegate only when a | ||
| * {@link Predicate} is true (or false, according to {@code negate}). | ||
| * @param <R> | ||
| */ | ||
| class PredicatedTransformation<R extends ConnectRecord<R>> implements Transformation<R> { | ||
|
|
||
| static final String PREDICATE_CONFIG = "predicate"; | ||
| static final String NEGATE_CONFIG = "negate"; | ||
| Predicate<R> predicate; | ||
| Transformation<R> delegate; | ||
| boolean negate; | ||
|
|
||
| PredicatedTransformation(Predicate<R> predicate, boolean negate, Transformation<R> delegate) { | ||
| this.predicate = predicate; | ||
| this.negate = negate; | ||
| this.delegate = delegate; | ||
| } | ||
|
|
||
| @Override | ||
| public void configure(Map<String, ?> configs) { | ||
| throw new ConnectException(PredicatedTransformation.class.getName() + ".configure() " + | ||
| "should never be called directly."); | ||
| } | ||
|
|
||
| @Override | ||
| public R apply(R record) { | ||
| if (negate ^ predicate.test(record)) { | ||
| return delegate.apply(record); | ||
| } | ||
| return record; | ||
| } | ||
|
|
||
| @Override | ||
| public ConfigDef config() { | ||
| throw new ConnectException(PredicatedTransformation.class.getName() + ".config() " + | ||
| "should never be called directly."); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| Utils.closeQuietly(delegate, "predicated"); | ||
| Utils.closeQuietly(predicate, "predicate"); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "PredicatedTransformation{" + | ||
| "predicate=" + predicate + | ||
| ", delegate=" + delegate + | ||
| ", negate=" + negate + | ||
| '}'; | ||
| } | ||
| } |
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.