Class LogicalTypeToDdlConverter

java.lang.Object
io.confluent.kafka.schemaregistry.type.logical.LogicalTypeToDdlConverter

public final class LogicalTypeToDdlConverter extends Object
Emits a LogicalType as DDL text — the inverse of LogicalTypesSchemaVisitor. Output is canonical (one statement per line; struct bodies multi-line when more than two fields). Round-trips through the visitor produce an equivalent LogicalType.

Lossy points (intentional, matching visitor capability):

  • External references have no syntactic marker — they're inferred on read-back from usage. USING TYPE statements survive (carrying the wire-format URI binding) but bare externals (no URI) are implicit, identified by appearing in a type position without a matching local STRUCT/ENUM.
  • Path-keyed defaultValues aren't re-emitted; field-level defaults survive via Schema.Field.getDefaultValue().
  • The single-root sugar is detected and the trailing root-registration TYPE statement is elided when it would be redundant. There is no multi-root UNION sugar: when several independent types are unreferenced, root inference selects the first declared and the rest remain peer named types; a UNION-of-named-types root must be written explicitly (TYPE UNION(...)).

A named inline root — a bare STRUCT/ENUM carrying LogicalType.getName() (e.g. an unwrapped Protobuf message) — is emitted as a named declaration and round-trips: the visitor unwraps a leaf named root back to a bare body carrying LogicalType.name (see LogicalTypesSchemaVisitor.maybeUnwrapNamedRoot), so the bare-root + name shape is preserved through LT → DDL → LT.