Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When a Transformation is configured with the new ?typepredicate parameter its application will happen conditionally. The value of the ?typepredicate parameter will be the name of a concrete class implementing the Predicate interfacepredicate defined under the ?predicates prefix. Configuration for the predicate will come from all other configuration parameters which start starting with '?'the same ?predicates... analogous to how the transformations in a transformation chain are configured. These will be supplied to the configure(Map) method, but with the initial '?' in the parameter name removed.

...

Code Block
transforms: t2
transforms.t2?predicate: has-my-prefix
transforms.t2?negate: true
transforms.t2.type: org.apache.kafka.connect.transforms.ExtractField$Key
transforms.t2.field: c1
?predicates: has-my-prefix
?predicates.has-my-prefix.type: org.apache.kafka.connect.predicates.TopicNameMatch
?predicates.has-my-prefix.pattern: my-prefix-.*

The transform t2 is only evaluated when the predicate has-my-prefix is false (the negate parameter). That predicate is configured by the keys with prefix ?predicates.has-my-prefix. The predicate class is org.apache.kafka.connect.predicates.TopicNameMatch. The ExtractField$Key and it's pattern parameter has the value my-prefix-.* . Thus the SMT will be applied only to records where the topic name does not  (the negate parameter) start with my-prefix-  (the pattern parameter).

The benefit of defining the predicate separately from the transform is it makes it easier to apply the same predicate to multiple transforms, or to have one set of transforms predicated on one predicate and another set of transforms predicated on that predicates negation.

The Filter SMT

A new Filter transformation will be added in the existing org.apache.kafka.connect.transforms package. This will return null from apply(ConnectRecord). This is not of much use on its own, but is intended to applied conditionally as described above. This will allow messages to be filtered according to the predicate.

...