Class LogicalTypeChecker
LogicalType against a downstream consumer's rules.
validate(io.confluent.kafka.schemaregistry.type.logical.policy.LogicalTypeChecker.Mode, io.confluent.kafka.schemaregistry.type.logical.LogicalType) takes one schema and asks whether the consumer can use it at all.
compare(io.confluent.kafka.schemaregistry.type.logical.policy.LogicalTypeChecker.Mode, io.confluent.kafka.schemaregistry.type.logical.LogicalType, io.confluent.kafka.schemaregistry.type.logical.LogicalType) takes two and asks whether the change between them is safe. The rules
live in ValidityChecker and CompatibilityChecker respectively; read those for the
rules, call this for the API.
A caller registering a schema needs both. Neither subsumes the other: a schema whose decimal precision exceeds what the consumer supports is unusable whether or not it changed, so a pairwise check alone lets it through on a first registration and on any later one that leaves the offending column untouched.
ValidityResult validity = LogicalTypeChecker.validate(mode, update);
CompatibilityResult compatibility = previous == null
? CompatibilityResult.compatible()
: LogicalTypeChecker.compare(mode, previous, update);
if (!validity.isValid() || !compatibility.isCompatible()) {
// reject, reporting validity.describe() and compatibility.describe()
}
Both results collect every finding rather than stopping at the first.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe downstream consumer whose rules should be applied. -
Method Summary
Modifier and TypeMethodDescriptionstatic CompatibilityResultcompare(LogicalTypeChecker.Mode mode, LogicalType original, LogicalType update) Whetherupdatemay replaceoriginalundermode.static ValidityResultvalidate(LogicalTypeChecker.Mode mode, LogicalType type) Whethertypecan be used bymode's consumer at all.
-
Method Details
-
compare
public static CompatibilityResult compare(LogicalTypeChecker.Mode mode, LogicalType original, LogicalType update) Whetherupdatemay replaceoriginalundermode.Direction is BACKWARD: the
updateschema must be able to read data written with theoriginalschema. Says nothing about whether either schema is usable on its own terms — pair that withvalidate(io.confluent.kafka.schemaregistry.type.logical.policy.LogicalTypeChecker.Mode, io.confluent.kafka.schemaregistry.type.logical.LogicalType).- Parameters:
mode- which consumer's rules to applyoriginal- the currently registered schemaupdate- the proposed schema- Returns:
- every violation found, or
CompatibilityResult.compatible()if there are none
-
validate
Whethertypecan be used bymode's consumer at all.Independent of any previous version, so this is the only one of the two checks that can reject a subject's first registration.
- Parameters:
mode- which consumer's rules to applytype- the schema to validate- Returns:
- every violation found, or
ValidityResult.valid()if there are none
-