Package io.debezium.util
Interface SchemaNameAdjuster
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface @ThreadSafe public interface SchemaNameAdjuster
A adjuster for the names of change data message schemas. Currently, this solely implements the rules required for using these schemas in Avro messages. Avro rules for schema fullnames are as follows:- Each has a fullname that is composed of two parts; a name and a namespace. Equality of names is defined on the fullname.
- The name portion of a fullname, record field names, and enum symbols must start with a Latin letter or underscore character (e.g., [A-Z,a-z,_]); and subsequent characters must be Latin alphanumeric or the underscore (
_
) characters (e.g., [A-Z,a-z,0-9,_]).- A namespace is a dot-separated sequence of such names.
- Equality of names (including field names and enum symbols) as well as fullnames is case-sensitive.
A
SchemaNameAdjuster
can determine if the supplied fullname follows these Avro rules.- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
SchemaNameAdjuster.ReplacementFunction
Function used to determine the replacement for a character that is not valid per Avro rules.static interface
SchemaNameAdjuster.ReplacementOccurred
Function used to report that an original value was replaced with an Avro-compatible string.
-
Field Summary
Fields Modifier and Type Field Description static SchemaNameAdjuster
DEFAULT
static org.slf4j.Logger
LOGGER
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description String
adjust(String proposedName)
Convert the proposed string to a valid Avro fullname, replacing all invalid characters with the underscore ('_') character.static SchemaNameAdjuster
create()
Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced with a valid fullname, and throws an error if the replacement conflicts with that of a different original.static SchemaNameAdjuster
create(char replacement, SchemaNameAdjuster.ReplacementOccurred uponReplacement)
Create a stateful Avro fullname adjuster that calls the suppliedSchemaNameAdjuster.ReplacementOccurred
function when an invalid fullname is seen and replaced with a valid fullname.static SchemaNameAdjuster
create(SchemaNameAdjuster.ReplacementFunction function, SchemaNameAdjuster.ReplacementOccurred uponReplacement)
Create a stateful Avro fullname adjuster that calls the suppliedSchemaNameAdjuster.ReplacementOccurred
function when an invalid fullname is seen and replaced with a valid fullname.static SchemaNameAdjuster
create(SchemaNameAdjuster.ReplacementOccurred uponConflict)
Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced with a valid fullname.static SchemaNameAdjuster
create(String replacement, SchemaNameAdjuster.ReplacementOccurred uponReplacement)
Create a stateful Avro fullname adjuster that calls the suppliedSchemaNameAdjuster.ReplacementOccurred
function when an invalid fullname is seen and replaced with a valid fullname.static SchemaNameAdjuster
defaultAdjuster()
Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced with a valid fullname and throws an exception.static boolean
isValidFullname(String fullname)
Determine if the supplied string is a valid Avro namespace.static boolean
isValidFullnameFirstCharacter(char c)
Determine if the supplied character is a valid first character for Avro fullnames.static boolean
isValidFullnameNonFirstCharacter(char c)
Determine if the supplied character is a valid non-first character for Avro fullnames.static String
validFullname(String proposedName)
Convert the proposed string to a valid Avro fullname, replacing all invalid characters with the underscore ('_') character.static String
validFullname(String proposedName, SchemaNameAdjuster.ReplacementFunction replacement)
Convert the proposed string to a valid Avro fullname, using the supplied function to replace all invalid characters.static String
validFullname(String proposedName, SchemaNameAdjuster.ReplacementFunction replacement, SchemaNameAdjuster.ReplacementOccurred uponReplacement)
Convert the proposed string to a valid Avro fullname, using the supplied function to replace all invalid characters.static String
validFullname(String proposedName, String replacement)
Convert the proposed string to a valid Avro fullname, replacing all invalid characters with the supplied string.
-
-
-
Field Detail
-
LOGGER
static final org.slf4j.Logger LOGGER
-
DEFAULT
static final SchemaNameAdjuster DEFAULT
-
-
Method Detail
-
adjust
String adjust(String proposedName)
Convert the proposed string to a valid Avro fullname, replacing all invalid characters with the underscore ('_') character.- Parameters:
proposedName
- the proposed fullname; may not be null- Returns:
- the valid fullname for Avro; never null
-
defaultAdjuster
static SchemaNameAdjuster defaultAdjuster()
Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced with a valid fullname and throws an exception. This method replaces all invalid characters with the underscore character ('_').- Returns:
- the validator; never null
-
create
static SchemaNameAdjuster create()
Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced with a valid fullname, and throws an error if the replacement conflicts with that of a different original. This method replaces all invalid characters with the underscore character ('_').- Parameters:
logger
- the logger to use; may not be null * @return the validator; never null
-
create
static SchemaNameAdjuster create(SchemaNameAdjuster.ReplacementOccurred uponConflict)
Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced with a valid fullname. This method replaces all invalid characters with the underscore character ('_').- Parameters:
uponConflict
- the function to be called when there is a conflict and after that conflict is logged; may be null- Returns:
- the validator; never null
-
create
static SchemaNameAdjuster create(char replacement, SchemaNameAdjuster.ReplacementOccurred uponReplacement)
Create a stateful Avro fullname adjuster that calls the suppliedSchemaNameAdjuster.ReplacementOccurred
function when an invalid fullname is seen and replaced with a valid fullname.- Parameters:
replacement
- the character that should be used to replace all invalid charactersuponReplacement
- the function called each time the original fullname is replaced; may be null- Returns:
- the adjuster; never null
-
create
static SchemaNameAdjuster create(String replacement, SchemaNameAdjuster.ReplacementOccurred uponReplacement)
Create a stateful Avro fullname adjuster that calls the suppliedSchemaNameAdjuster.ReplacementOccurred
function when an invalid fullname is seen and replaced with a valid fullname.- Parameters:
replacement
- the character sequence that should be used to replace all invalid charactersuponReplacement
- the function called each time the original fullname is replaced; may be null- Returns:
- the adjuster; never null
-
create
static SchemaNameAdjuster create(SchemaNameAdjuster.ReplacementFunction function, SchemaNameAdjuster.ReplacementOccurred uponReplacement)
Create a stateful Avro fullname adjuster that calls the suppliedSchemaNameAdjuster.ReplacementOccurred
function when an invalid fullname is seen and replaced with a valid fullname.- Parameters:
function
- the replacement functionuponReplacement
- the function called each time the original fullname is replaced; may be null- Returns:
- the adjuster; never null
-
isValidFullname
static boolean isValidFullname(String fullname)
Determine if the supplied string is a valid Avro namespace.- Parameters:
fullname
- the name to be used as an Avro fullname; may not be null- Returns:
true
if the fullname satisfies Avro rules, orfalse
otherwise
-
isValidFullnameFirstCharacter
static boolean isValidFullnameFirstCharacter(char c)
Determine if the supplied character is a valid first character for Avro fullnames.- Parameters:
c
- the character- Returns:
true
if the character is a valid first character of an Avro fullname, orfalse
otherwise- See Also:
isValidFullname(String)
-
isValidFullnameNonFirstCharacter
static boolean isValidFullnameNonFirstCharacter(char c)
Determine if the supplied character is a valid non-first character for Avro fullnames.- Parameters:
c
- the character- Returns:
true
if the character is a valid non-first character of an Avro fullname, orfalse
otherwise- See Also:
isValidFullname(String)
-
validFullname
static String validFullname(String proposedName)
Convert the proposed string to a valid Avro fullname, replacing all invalid characters with the underscore ('_') character.- Parameters:
proposedName
- the proposed fullname; may not be null- Returns:
- the valid fullname for Avro; never null
-
validFullname
static String validFullname(String proposedName, String replacement)
Convert the proposed string to a valid Avro fullname, replacing all invalid characters with the supplied string.- Parameters:
proposedName
- the proposed fullname; may not be nullreplacement
- the character sequence that should be used to replace all invalid characters- Returns:
- the valid fullname for Avro; never null
-
validFullname
static String validFullname(String proposedName, SchemaNameAdjuster.ReplacementFunction replacement)
Convert the proposed string to a valid Avro fullname, using the supplied function to replace all invalid characters.- Parameters:
proposedName
- the proposed fullname; may not be nullreplacement
- the character sequence that should be used to replace all invalid characters- Returns:
- the valid fullname for Avro; never null
-
validFullname
static String validFullname(String proposedName, SchemaNameAdjuster.ReplacementFunction replacement, SchemaNameAdjuster.ReplacementOccurred uponReplacement)
Convert the proposed string to a valid Avro fullname, using the supplied function to replace all invalid characters.- Parameters:
proposedName
- the proposed fullname; may not be nullreplacement
- the character sequence that should be used to replace all invalid charactersuponReplacement
- the function to be called every time the proposed name is invalid and replaced; may be null- Returns:
- the valid fullname for Avro; never null
-
-