@@ -140,7 +140,7 @@ private static final CelCompiler CEL_COMPILER =
140140// CelRuntime can also be initialized statically and cached just like the
141141// compiler.
142142private static final CelRuntime CEL_RUNTIME =
143- CelRuntimeFactory . standardCelRuntimeBuilder ()
143+ CelRuntimeFactory . plannerRuntimeBuilder ()
144144 .setOptions(CEL_OPTIONS )
145145 .build();
146146```
@@ -232,7 +232,7 @@ Copy the following into eval method:
232232Object eval(CelAbstractSyntaxTree ast) {
233233 // Construct a CelRuntime instance
234234 // CelRuntime is immutable just like the compiler and can be moved to a static final member.
235- CelRuntime celRuntime = CelRuntimeFactory . standardCelRuntimeBuilder (). build();
235+ CelRuntime celRuntime = CelRuntimeFactory . plannerRuntimeBuilder (). build();
236236
237237 try {
238238 // Plan the program
@@ -314,7 +314,7 @@ Let's make the evaluation work now. Copy into the eval method:
314314 * @throws IllegalArgumentException If the compiled expression in AST fails to evaluate.
315315 */
316316Object eval(CelAbstractSyntaxTree ast, Map<String , ?> parameterValues) {
317- CelRuntime celRuntime = CelRuntimeFactory . standardCelRuntimeBuilder (). build();
317+ CelRuntime celRuntime = CelRuntimeFactory . plannerRuntimeBuilder (). build();
318318 try {
319319 CelRuntime . Program program = celRuntime. createProgram(ast);
320320
@@ -510,7 +510,7 @@ CelAbstractSyntaxTree compile(String expression) {
510510 */
511511Object eval (CelAbstractSyntaxTree ast , Map<String , ?> parameterValues ) {
512512 CelRuntime celRuntime =
513- CelRuntimeFactory . standardCelRuntimeBuilder ()
513+ CelRuntimeFactory . plannerRuntimeBuilder ()
514514 // Provide the custom `contains` function implementation here.
515515 .build();
516516
@@ -590,7 +590,7 @@ Provide the function implementation to the runtime using the .addFunctionBinding
590590 */
591591Object eval (CelAbstractSyntaxTree ast , Map<String , ?> parameterValues ) {
592592 CelRuntime celRuntime =
593- CelRuntimeFactory . standardCelRuntimeBuilder ()
593+ CelRuntimeFactory . plannerRuntimeBuilder ()
594594 .addFunctionBindings(
595595 CelFunctionBinding . from(
596596 " map_contains_key_value" ,
@@ -1136,7 +1136,7 @@ private static final CelCompiler CEL_COMPILER =
11361136 .addMessageTypes(AttributeContext . Request . getDescriptor())
11371137 .build();
11381138private static final CelRuntime CEL_RUNTIME =
1139- CelRuntimeFactory . standardCelRuntimeBuilder ()
1139+ CelRuntimeFactory . plannerRuntimeBuilder ()
11401140 .addMessageTypes(AttributeContext . Request . getDescriptor())
11411141 .build();
11421142```
@@ -1362,11 +1362,11 @@ public void optimize_commonSubexpressionElimination_success() throws Exception {
13621362}
13631363```
13641364
1365- CSE will rewrite this expression using a specialized internal function
1366- ` cel.@block ` . The first argument contain a list duplicate subexpressions
1367- and the second argument is the rewritten result expression that is semantically
1368- the same as the original expression . The subexpressions are lazily evaluated and
1369- memoized when accessed by index (e.g: ` @index0 ` ).
1365+ CSE optimizes the expression by rewriting it to use a specialized internal
1366+ function ` cel.@block ` . This function takes a list of duplicate subexpressions
1367+ as its first argument, and a semantically equivalent rewritten expression as
1368+ its second . The subexpressions are lazily evaluated and memoized when accessed
1369+ by index (e.g., ` @index0 ` ).
13701370
13711371Make the following changes in ` Exercise8.java ` :
13721372
@@ -1375,19 +1375,10 @@ private static final CelOptimizer CEL_OPTIMIZER =
13751375 CelOptimizerFactory . standardCelOptimizerBuilder(CEL_COMPILER , CEL_RUNTIME )
13761376 .addAstOptimizers(
13771377 ConstantFoldingOptimizer . getInstance(),
1378- SubexpressionOptimizer . newInstance(
1379- SubexpressionOptimizerOptions . newBuilder(). enableCelBlock(true ). build()))
1378+ SubexpressionOptimizer . getInstance())
13801379 .build();
13811380```
13821381
1383- As seen here, the usage of ` cel.block ` must explicitly be enabled as it is
1384- only supported in CEL-Java as of now. Disabling ` cel.block ` will instead rewrite
1385- the AST using cascaded ` cel.bind ` macros. Prefer using the block format if
1386- possible as it is a more efficient format for evaluation.
1387-
1388- > [ !CAUTION]
1389- > You MUST disable ` cel.block ` if you are targeting ` cel-go ` or ` cel-cpp ` for the runtime until its support has been added in those stacks.
1390-
13911382Re-run the tests to confirm that they pass.
13921383
13931384## Custom AST Validation
0 commit comments