java.lang.Object
io.confluent.kafka.schemaregistry.rules.cel.CelUtils

public final class CelUtils extends Object
Shared CEL helpers used by both the transform-path executor (CelExecutor) and the validation-path executor (CelValidator). All methods are stateless.
  • Method Details

    • buildProgram

      public static dev.cel.runtime.CelRuntime.Program buildProgram(CelUtils.ScriptType type, String expr, Object schemaHint, List<dev.cel.common.CelVarDecl> varDecls) throws dev.cel.common.CelValidationException, dev.cel.runtime.CelEvaluationException
      Build a CEL CelRuntime.Program for (type, expr, schemaHint, varDecls). The compiler is configured with the standard library, our BuiltinLibrary, and any format-specific type registration; the runtime mirrors the compile-side configuration so resolved overload IDs find their bindings.

      For AVRO and JSON values, callers should pre-convert native values (GenericRecord, Jackson JsonNode, etc.) to CEL-native shapes (Map / List / scalar) via toCelValue(Object) before binding. Field access (this.field, this["field"]) then works through CEL's built-in map semantics — no custom type provider is required.

      Throws:
      dev.cel.common.CelValidationException
      dev.cel.runtime.CelEvaluationException
    • buildProgram

      public static dev.cel.runtime.CelRuntime.Program buildProgram(CelUtils.ScriptType type, String expr, Object schemaHint, List<dev.cel.common.CelVarDecl> varDecls, CelUtils.RegexEngine regexEngine) throws dev.cel.common.CelValidationException, dev.cel.runtime.CelEvaluationException
      Throws:
      dev.cel.common.CelValidationException
      dev.cel.runtime.CelEvaluationException
    • buildCompiledRule

      public static CelUtils.CompiledRule buildCompiledRule(CelUtils.ScriptType type, String expr, Object schemaHint, List<dev.cel.common.CelVarDecl> varDecls, CelUtils.RegexEngine regexEngine) throws dev.cel.common.CelValidationException, dev.cel.runtime.CelEvaluationException
      Like buildProgram(io.confluent.kafka.schemaregistry.rules.cel.CelUtils.ScriptType, java.lang.String, java.lang.Object, java.util.List<dev.cel.common.CelVarDecl>) but exposes the compiled AST's result-type CelKind alongside the runnable program. Lets callers (notably CelValidator) reject rules whose result type doesn't fit their contract, at compile time rather than first eval.
      Throws:
      dev.cel.common.CelValidationException
      dev.cel.runtime.CelEvaluationException
    • toVarDecls

      public static List<dev.cel.common.CelVarDecl> toVarDecls(Map<String,dev.cel.common.types.CelType> args)
      Convenience wrapper to construct CelVarDecl list from a name→type map, preserving insertion order.
    • toDeclTypes

      public static Map<String,dev.cel.common.types.CelType> toDeclTypes(Map<String,Object> args)
      Build a name→CelType map by inferring each value's type. Insertion order is preserved (uses LinkedHashMap) so generated declarations match argument binding order.
    • findCelType

      public static dev.cel.common.types.CelType findCelType(Object arg)
      Infer the CelType for a runtime value. Used to declare this (and other variables) in the compiler so the type-checker can validate field access.
    • findCelTypeForAvroSchema

      public static dev.cel.common.types.CelType findCelTypeForAvroSchema(org.apache.avro.Schema schema)
      Map an Avro Schema to a CelType.
    • findCelTypeForClass

      public static dev.cel.common.types.CelType findCelTypeForClass(Class<?> type)
      Map a Java Class to a CelType. Used when the value isn't a GenericContainer or proto Message (i.e., a JSON-derived primitive value or a primitive Avro/Proto field bound to this).
    • toCelValue

      public static Object toCelValue(Object value)
      Convert a native value to a CEL-compatible shape:
      • IndexedRecord (covers both GenericRecord and SpecificRecord) → JDK Map (Google cel-java's runtime selects fields on Maps natively)
      • Utf8 / GenericEnumSymbolString
      • Narrow numeric types (Integer, Short, Byte, Float) widened to CEL's natural widths (long / double)
      • byte[] / ByteStringCelByteString (CEL bytes literals only compare equal to other CelByteStrings)
      • Lists/maps recursively converted
      Other values (proto Messages, BigDecimal, primitives at correct width, etc.) pass through unchanged.
    • toCelValueForJson

      public static Object toCelValueForJson(Object value, com.fasterxml.jackson.databind.ObjectMapper mapper)
      JSON-flavored variant of toCelValue(Object): additionally converts Jackson JsonNode and arbitrary POJOs to maps via the supplied ObjectMapper. Used on the JSON validation/transform path where the value passed in might be a bean — we materialize beans as maps so the CEL runtime's native map field-access path applies.

      Primitives, strings, byte buffers, proto Messages, Avro GenericRecord and Utf8 delegate to toCelValue(Object).