Class ConstraintValidationContext

java.lang.Object
io.confluent.kafka.schemaregistry.type.logical.constraint.ConstraintValidationContext

public final class ConstraintValidationContext extends Object
Context passed to ConstraintToCelTranslator for parse-time validation of CHECK constraint expressions.

Carries:

  • The set of column names the expression may reference, mapped to their schemas. For column-level constraints this contains only the attached field; for table-level constraints, every field in the surrounding struct.
  • Runtime-injected variables (currently only now for CURRENT_TIMESTAMP) — recognized for column-ref resolution but not type-checked since they're injected outside the LT's schema.

Used by the translator's strict validation pass (per design decision 11) to reject unknown column refs, non-boolean root expressions, and mismatched comparison types — all at parse time, with source-position information in the error message.

  • Method Details

    • isRuntimeVar

      public static boolean isRuntimeVar(String name)
      True if name is a runtime-injected variable (e.g. now for CURRENT_TIMESTAMP). Used by macro arg validation to refuse iter-var names that would shadow these runtime variables for the macro body's scope.
    • withBinding

      public ConstraintValidationContext withBinding(String name)
      Returns a derived context with name added as a known binding (e.g., a CEL macro iteration variable). Schema is unknown. Type-aware passes will defer to runtime for refs to name. Prefer withBinding(String, Schema) when the type is known.
    • withBinding

      public ConstraintValidationContext withBinding(String name, Schema type)
      Returns a derived context with name bound to type — e.g., a CEL macro iteration variable typed as the collection's element type. A null type registers the name without type info (validators can still resolve presence but not type). Inherits isColumnLevel() from the outer context.
    • withNamedTypes

      public ConstraintValidationContext withNamedTypes(Map<String,Schema> types)
      Returns a derived context with namedTypes attached. Used by the DDL visitor to make previously-declared named-type bodies available for NAMED_TYPE_REF resolution during indirection validation.
    • resolveNamedType

      public Schema resolveNamedType(Schema schema)
      Resolve a NAMED_TYPE_REF's qualified name to its underlying STRUCT/ENUM body, or null if not registered. Returns schema unchanged when schema is not a NAMED_TYPE_REF.
    • columnLevel

      public static ConstraintValidationContext columnLevel(String fieldName, Schema fieldSchema)
      Context for a column-level CHECK: only the attached field is in scope.
    • tableLevel

      public static ConstraintValidationContext tableLevel(List<Schema.Field> fields)
      Context for a table-level CHECK: all fields of the surrounding struct.
    • isColumnLevel

      public boolean isColumnLevel()
      True if this context corresponds to a column-level CHECK (the attached field is the only thing in scope). False for table-level. Macro derivations inherit the outer context's value.
    • isConstrainedColumn

      public boolean isConstrainedColumn(String name)
      True when name resolves to the column-level CHECK's constrained column — i.e., the placement is column-level, the name appears in the schema column map, AND it is not shadowed by a macro iter-var binding. Used by the skip-on-null contract: only the constrained column gets the "this is non-null at evaluation" guarantee; iter-var bindings inside macro bodies retain normal null semantics.
    • isColumn

      public boolean isColumn(String name)
      True if name resolves to a known schema column in this scope. Bindings shadow columns: an iter-var named the same as a column is NOT a column, so the protovalidate this/this.x prefix must NOT be applied to it. Used at emit time by visitColumnRef.
    • isKnown

      public boolean isKnown(String name)
      True if name is a valid root identifier in this context — a known column, an in-scope binding (e.g., macro iteration var), or a runtime-injected variable.
    • schemaOf

      public Schema schemaOf(String name)
      Schema for a known column or typed binding. Bindings shadow columns (an iter-var declaration overrides the outer column with the same name for the duration of the macro body). Returns null when name is a runtime-injected variable, an untyped binding, or unknown.
    • allowedNames

      public String allowedNames()
      Sorted list of valid column names for error message reporting. Excludes runtime variables.