Class CelExpr.CelComprehension
- java.lang.Object
-
- dev.cel.common.ast.CelExpr.CelComprehension
-
- Enclosing class:
- CelExpr
@Immutable public abstract static class CelExpr.CelComprehension extends java.lang.ObjectA comprehension expression applied to a list or map.Comprehensions are not part of the core syntax, but enabled with macros. A macro matches a specific call signature within a parsed AST and replaces the call with an alternate AST block. Macro expansion happens at parse time.
The following macros are supported within CEL:
Aggregate type macros may be applied to all elements in a list or all keys in a map:
`all`, `exists`, `exists_one` - test a predicate expression against the inputs and return `true` if the predicate is satisfied for all, any, or only one value `list.all(x, x < 10)`. `filter` - test a predicate expression against the inputs and return the subset of elements which satisfy the predicate: `payments.filter(p, p > 1000)`. `map` - apply an expression to all elements in the input and return the output aggregate type: `[1, 2, 3].map(i, i * i)`.
The `has(m.x)` macro tests whether the property `x` is present in struct `m`. The semantics of this macro depend on the type of `m`. For proto2 messages `has(m.x)` is defined as 'defined, but not set`. For proto3, the macro tests whether the property is set to its default. For map and struct types, the macro tests whether the property `x` is defined on `m`.
Comprehension evaluation can be best visualized as the following pseudocode:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCelExpr.CelComprehension.BuilderBuilder for Comprehension.
-
Constructor Summary
Constructors Constructor Description CelComprehension()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract CelExpraccuInit()The initial value of the accumulator.abstract java.lang.StringaccuVar()The name of the variable used for accumulation of the result.abstract CelExpriterRange()The range over which var iterates.abstract java.lang.StringiterVar()The name of the iteration variable.abstract CelExprloopCondition()An expression which can contain iter_var and accu_var.abstract CelExprloopStep()An expression which can contain iter_var and accu_var.static CelExpr.CelComprehension.BuildernewBuilder()abstract CelExprresult()An expression which can contain accu_var.abstract CelExpr.CelComprehension.BuildertoBuilder()
-
-
-
Method Detail
-
iterVar
public abstract java.lang.String iterVar()
The name of the iteration variable.
-
iterRange
public abstract CelExpr iterRange()
The range over which var iterates.
-
accuVar
public abstract java.lang.String accuVar()
The name of the variable used for accumulation of the result.
-
accuInit
public abstract CelExpr accuInit()
The initial value of the accumulator.
-
loopCondition
public abstract CelExpr loopCondition()
An expression which can contain iter_var and accu_var.Returns false when the result has been computed and may be used as a hint to short-circuit the remainder of the comprehension.
-
loopStep
public abstract CelExpr loopStep()
An expression which can contain iter_var and accu_var.Computes the next value of accu_var.
-
result
public abstract CelExpr result()
An expression which can contain accu_var.Computes the result.
-
toBuilder
public abstract CelExpr.CelComprehension.Builder toBuilder()
-
newBuilder
public static CelExpr.CelComprehension.Builder newBuilder()
-
-