-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from rhauch/dbz-29b
DBZ-29 Refactored ColumnMappers
- Loading branch information
Showing
13 changed files
with
501 additions
and
130 deletions.
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
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
24 changes: 0 additions & 24 deletions
24
debezium-core/src/main/java/io/debezium/relational/ColumnMapper.java
This file was deleted.
Oops, something went wrong.
136 changes: 77 additions & 59 deletions
136
debezium-core/src/main/java/io/debezium/relational/TableSchemaBuilder.java
Large diffs are not rendered by default.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
debezium-core/src/main/java/io/debezium/relational/mapping/ColumnMapper.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,46 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.relational.mapping; | ||
|
||
import org.apache.kafka.connect.data.Field; | ||
import org.apache.kafka.connect.data.SchemaBuilder; | ||
|
||
import io.debezium.config.Configuration; | ||
import io.debezium.relational.Column; | ||
import io.debezium.relational.ValueConverter; | ||
|
||
/** | ||
* A factory for a function used to map values of a column. | ||
* | ||
* @author Randall Hauch | ||
*/ | ||
@FunctionalInterface | ||
public interface ColumnMapper { | ||
|
||
/** | ||
* Initialize the ColumnMapper instance based upon the connector's configuration. | ||
* @param config the connector's configuration | ||
*/ | ||
default void initialize( Configuration config ) { | ||
// do nothing | ||
} | ||
|
||
/** | ||
* Create for the given column a function that maps values. | ||
* | ||
* @param column the column description; never null | ||
* @return the function that converts the value; may be null | ||
*/ | ||
ValueConverter create(Column column); | ||
|
||
/** | ||
* Optionally annotate the schema with properties to better capture the mapping behavior. | ||
* @param schemaBuilder the builder for the {@link Field}'s schema; never null | ||
*/ | ||
default void alterFieldSchema( SchemaBuilder schemaBuilder) { | ||
// do nothing | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
debezium-core/src/main/java/io/debezium/relational/mapping/MaskStrings.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,73 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.relational.mapping; | ||
|
||
import java.sql.Types; | ||
|
||
import org.apache.kafka.connect.data.SchemaBuilder; | ||
|
||
import io.debezium.annotation.Immutable; | ||
import io.debezium.relational.Column; | ||
import io.debezium.relational.ValueConverter; | ||
|
||
/** | ||
* A {@link ColumnMapper} implementation that ensures that string values are masked by a predefined value. | ||
* | ||
* @author Randall Hauch | ||
*/ | ||
public class MaskStrings implements ColumnMapper { | ||
|
||
private final MaskingValueConverter converter; | ||
|
||
/** | ||
* Create a {@link ColumnMapper} that masks string values with a predefined value. | ||
* | ||
* @param maskValue the value that should be used in place of the actual value; may not be null | ||
* @throws IllegalArgumentException if the {@code maxLength} is not positive | ||
*/ | ||
public MaskStrings(String maskValue) { | ||
if (maskValue == null) throw new IllegalArgumentException("Mask value may not be null"); | ||
this.converter = new MaskingValueConverter(maskValue); | ||
} | ||
|
||
@Override | ||
public ValueConverter create(Column column) { | ||
switch (column.jdbcType()) { | ||
case Types.CHAR: // variable-length | ||
case Types.VARCHAR: // variable-length | ||
case Types.LONGVARCHAR: // variable-length | ||
case Types.CLOB: // variable-length | ||
case Types.NCHAR: // fixed-length | ||
case Types.NVARCHAR: // fixed-length | ||
case Types.LONGNVARCHAR: // fixed-length | ||
case Types.NCLOB: // fixed-length | ||
case Types.DATALINK: | ||
return converter; | ||
default: | ||
return ValueConverter.passthrough(); | ||
} | ||
} | ||
|
||
@Override | ||
public void alterFieldSchema(SchemaBuilder schemaBuilder) { | ||
schemaBuilder.parameter("masked", "true"); | ||
} | ||
|
||
@Immutable | ||
protected static final class MaskingValueConverter implements ValueConverter { | ||
protected final String maskValue; | ||
|
||
public MaskingValueConverter(String maskValue) { | ||
this.maskValue = maskValue; | ||
assert this.maskValue != null; | ||
} | ||
|
||
@Override | ||
public Object convert(Object value) { | ||
return maskValue; | ||
} | ||
} | ||
} |
Oops, something went wrong.