Class ConstraintToCelTranslator

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

public final class ConstraintToCelTranslator extends Object
Public entry point for translating a parsed SQL CHECK expression (postgres-derived subset) to a CEL expression string.

The work is split across siblings in this package:

  • ConstraintValidator — pre-emit validation passes (boolean root, column-ref resolution, type-aware checks).
  • ConstraintEmitter — cascade walkers that turn the parse tree into CEL fragments.
  • ConstraintFunctions — function dispatch and special-syntax forms (CAST, EXTRACT, SUBSTRING, etc.).
  • ConstraintResolver — best-effort type/literal resolution used by both validators and emitters.
  • ConstraintPatterns — pure SQL→CEL string/regex helpers.

This file holds: the public translate(io.confluent.kafka.schemaregistry.type.logical.generated.LogicalTypesParser.Check_exprContext, io.confluent.kafka.schemaregistry.type.logical.constraint.ConstraintValidationContext) entry, the per-translation EMIT_VCTX ThreadLocal, the located-error builder, and the colid unquoting helpers. Everyone in the constraint package shares those — keeping them here avoids an extra utility file for three small helpers.

The translator is purely text-emitting — no CEL evaluator is bundled or required. The output is a well-formed CEL expression string that consumers (the SR rules engine, Flink runtime, etc.) can evaluate with their own CEL evaluator.

  • Method Details

    • translate

      public static String translate(LogicalTypesParser.Check_exprContext ctx, ConstraintValidationContext validationContext)
      Translate a check_expr parse tree to CEL. Runs strict parse-time validation passes (boolean root, column-ref resolution, ordered-type and cross-type checks, macro arity, etc.) before emitting; errors include source position. Column refs are emitted using the protovalidate this convention based on the placement signaled by validationContext: column-level CHECK refs collapse to this; table-level refs become this.<col>.