Class ConstraintValidationContext
java.lang.Object
io.confluent.kafka.schemaregistry.type.logical.constraint.ConstraintValidationContext
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
nowforCURRENT_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 Summary
Modifier and TypeMethodDescriptionSorted list of valid column names for error message reporting.static ConstraintValidationContextcolumnLevel(String fieldName, Schema fieldSchema) Context for a column-level CHECK: only the attached field is in scope.booleanTrue ifnameresolves to a known schema column in this scope.booleanTrue if this context corresponds to a column-level CHECK (the attached field is the only thing in scope).booleanisConstrainedColumn(String name) True whennameresolves 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.booleanTrue ifnameis a valid root identifier in this context — a known column, an in-scope binding (e.g., macro iteration var), or a runtime-injected variable.static booleanisRuntimeVar(String name) True ifnameis a runtime-injected variable (e.g.resolveNamedType(Schema schema) Resolve aNAMED_TYPE_REF's qualified name to its underlying STRUCT/ENUM body, or null if not registered.Schema for a known column or typed binding.static ConstraintValidationContexttableLevel(List<Schema.Field> fields) Context for a table-level CHECK: all fields of the surrounding struct.withBinding(String name) Returns a derived context withnameadded as a known binding (e.g., a CEL macro iteration variable).withBinding(String name, Schema type) Returns a derived context withnamebound totype— e.g., a CEL macro iteration variable typed as the collection's element type.withNamedTypes(Map<String, Schema> types) Returns a derived context withnamedTypesattached.
-
Method Details
-
isRuntimeVar
True ifnameis a runtime-injected variable (e.g.nowforCURRENT_TIMESTAMP). Used by macro arg validation to refuse iter-var names that would shadow these runtime variables for the macro body's scope. -
withBinding
Returns a derived context withnameadded as a known binding (e.g., a CEL macro iteration variable). Schema is unknown. Type-aware passes will defer to runtime for refs toname. PreferwithBinding(String, Schema)when the type is known. -
withBinding
Returns a derived context withnamebound totype— e.g., a CEL macro iteration variable typed as the collection's element type. A nulltyperegisters the name without type info (validators can still resolve presence but not type). InheritsisColumnLevel()from the outer context. -
withNamedTypes
Returns a derived context withnamedTypesattached. Used by the DDL visitor to make previously-declared named-type bodies available forNAMED_TYPE_REFresolution during indirection validation. -
resolveNamedType
Resolve aNAMED_TYPE_REF's qualified name to its underlying STRUCT/ENUM body, or null if not registered. Returnsschemaunchanged whenschemais not aNAMED_TYPE_REF. -
columnLevel
Context for a column-level CHECK: only the attached field is in scope. -
tableLevel
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
True whennameresolves 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
True ifnameresolves 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 protovalidatethis/this.xprefix must NOT be applied to it. Used at emit time byvisitColumnRef. -
isKnown
True ifnameis 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
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 whennameis a runtime-injected variable, an untyped binding, or unknown. -
allowedNames
Sorted list of valid column names for error message reporting. Excludes runtime variables.
-