Class ToLogicalContext<T>

java.lang.Object
io.confluent.kafka.schemaregistry.type.logical.common.CycleContext<T>
io.confluent.kafka.schemaregistry.type.logical.common.ToLogicalContext<T>
Type Parameters:
T - the type used for cycle detection (e.g., org.apache.avro.Schema or String)

public final class ToLogicalContext<T> extends CycleContext<T>
Mutable context for converting a format-specific schema to logical type Schema. Wraps the input ParsedSchema and accumulates conversion-time state (named types — both local and lazy-promoted externals — plus union branch metadata and cycle tracking).

Named types vs externals. putNamedType(java.lang.String, io.confluent.kafka.schemaregistry.type.logical.Schema) populates the unified map fed to LogicalType.getNamedTypes(). Entries that originated from an external schema are also marked via addExternalType(java.lang.String) so the resulting LT can distinguish them via LogicalType.getExternalTypes(). Field handlers consult isExternalType(java.lang.String) to decide whether a NAMED_TYPE_REF body should be lazy-promoted as external (and re-emitted as an import on write) or treated as locally defined.

  • Field Details

    • MAX_TYPE_DEPTH

      public static final int MAX_TYPE_DEPTH
      Maximum type-nesting depth accepted when converting an external schema into a logical type. Deeply nested (but non-cyclic) inputs would otherwise recurse until the JVM stack overflows; the to-logical converters check this bound and raise a ValidationException instead. Unlike CHECK-constraint parsing (an iterative walk that can safely cap at a much higher depth), type conversion is genuinely recursive and consumes several stack frames per nesting level, so this cap sits well below the stack's frame budget to fire deterministically before exhaustion. A StackOverflowError backstop at each converter entry covers environments whose stack is smaller still.
      See Also:
  • Constructor Details

  • Method Details

    • getParsedSchema

      public ParsedSchema getParsedSchema()
    • getVersion

      public LogicalTypeVersion getVersion()
    • isV1

      public boolean isV1()
    • getReferences

      public List<SchemaReference> getReferences()
    • getUnionMetadata

      public Map<String,Object> getUnionMetadata()
    • setUnionMetadata

      public void setUnionMetadata(Map<String,Object> unionMetadata)
    • getNamedTypes

      public Map<String,Schema> getNamedTypes()
    • putNamedType

      public void putNamedType(String name, Schema schema)
    • hasNamedType

      public boolean hasNamedType(String name)
    • addExternalType

      public void addExternalType(String name)
      Mark name as an externally-defined named type (its body originated from a resolvedReferences entry rather than from the active schema). Used both at pre-walk time (to flag what's external) and at field-handler time (to propagate external status into the LT's externalTypes set).
    • isExternalType

      public boolean isExternalType(String name)
    • getExternalTypes

      public Set<String> getExternalTypes()
    • synthesizeRefName

      public String synthesizeRefName(String uri)
      Synthesize (or look up) a Ref<N> typeName for a non-canonical $ref URI. Same URI returns the same name; new URIs get the next available index that isn't already in namedTypes. The returned name is automatically registered as external and bound to uri via getExternalImports().
    • registerSyntheticExternal

      public void registerSyntheticExternal(String name, String uri)
      Direct registration for synthetic externals discovered from the active schema's $defs (entries carrying the logical.ref marker). Caller has the typeName and URI already; we just record the binding and mark the name as external.
    • getExternalImports

      public Map<String,String> getExternalImports()