Table of Contents |
---|
Status
Current state: Draft, JIRA exists with pull-request
...
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
Motivation
The existing MaskField SMT uses null value equivalent for all types of fields masked.
...
'replacement' param value, if specified in config, will be applied to all fields in the 'fields' param list. This way user can mask any string or numeric value with any literal of his choice.
Public Interfaces
New param 'replacement' will be added to the MaskField SMT config. Param is optional so this change is backward compatible.
...
With config described above there will be 3 transformations, first and second will replace value in a single field, while third will be applied to both 'office' and 'phone' fields.
Restrictions
If replacement provided cannot be converted to the target field type or field type is not supported then org.apache.kafka.connect.errors.DataException will be thrown.
...
Replacing Date, Map or List with custom value seems to be useless and makes conversion logic more complicated.
Proposed Changes
Add 'replacement' field to config definition:
...
Code Block | ||||
---|---|---|---|---|
| ||||
private static Object maskWithCustomReplacement(Object value, String replacement) { Function<String, ?> replacementMapper = REPLACEMENT_MAPPING_FUNC.get(value.getClass()); if (replacementMapper == null) { throw new DataException("Cannot mask value of type " + value.getClass() + " with custom replacement."); } try { return replacementMapper.apply(replacement); } catch (NumberFormatException ex) { throw new DataException("Unable to convert " + replacement + " (" + replacement.getClass() + ") to number", ex); } } |
Compatibility, Deprecation, and Migration Plan
- Positive impact on existing users: introducing custom replacement will make MaskField SMT applicable for wider variety of use-cases.
- We are not changing behavior but adding new features
- Support backward compatibility with an old config format
Rejected Alternatives
First version of the improvement, proposed in the PR, used JSON map of maskField → replacement, this approach had both pros and cons:
...