Class LogicalTypeConversion

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

public final class LogicalTypeConversion extends Object
Converts a logical types DDL script into the native schema it denotes.

Shared by everything that reads DDL, so that a script means the same thing wherever it is read -- in the registry, which converts a submitted body before storing it, and in a LogicalSchemaProvider, which converts one while parsing. Callers differ only in where they resolve references and what they do with the result, so those stay with them; everything that decides what the script means lives here.

Parsing and conversion are separate calls because a caller classifies a body before converting it, and splitting them lets it do both from a single parse.

  • Method Details

    • tryParse

      public static Optional<LogicalTypesParser.ScriptContext> tryParse(String text)
      Parses text as a DDL script, or returns empty if it is not one.

      This decides only the form of the body. A script that parses but is semantically invalid is still DDL, and says so when converted.

    • toNative

      public static ParsedSchema toNative(LogicalTypesParser.ScriptContext script, Schema schema, Map<String,String> resolvedReferences)
      Converts an already-parsed script into the native schema for schema's type, named after its subject and carrying its metadata, rule set and references.
      Parameters:
      script - the parsed script, from tryParse(String)
      schema - what was submitted: its subject names the converted root, and its schema type decides the target format
      resolvedReferences - the schema's references resolved to their definitions, which the caller looks up however it can
      Throws:
      ValidationException - if the script is not a valid logical type, or cannot be represented in the requested format
    • rowName

      public static String rowName(String subject)
      Derives the name given to a converted root that the script leaves anonymous. A script that names its root uses that name instead, so this applies only to a bare STRUCT.