Skip to content

Commit e5a9787

Browse files
l46kokcopybara-github
authored andcommitted
Update documentation and CEL-Java codelabs to use planner
PiperOrigin-RevId: 940712133
1 parent 0b2bf66 commit e5a9787

18 files changed

Lines changed: 25 additions & 25 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class HelloWorld {
8484
private static final CelCompiler CEL_COMPILER =
8585
CelCompilerFactory.standardCelCompilerBuilder().addVar("my_var", SimpleType.STRING).build();
8686
private static final CelRuntime CEL_RUNTIME =
87-
CelRuntimeFactory.standardCelRuntimeBuilder().build();
87+
CelRuntimeFactory.plannerRuntimeBuilder().build();
8888

8989
public void run() throws CelValidationException, CelEvaluationException {
9090
// Compile the expression into an Abstract Syntax Tree.
@@ -144,7 +144,7 @@ found in the [`CelCompilerBuilder`][9].
144144
Some CEL use cases only require parsing of an expression in order to be useful.
145145
For example, one example might want to check whether the expression contains any
146146
nested comprehensions, or possibly to pass the parsed expression to a C++ or Go
147-
binary for evaluation. Presently, Java does not support parse-only evaluation.
147+
binary for evaluation.
148148

149149
```java
150150
CelValidationResult parseResult =
@@ -231,7 +231,7 @@ Expressions can be evaluated using once they are type-checked/compiled by
231231
creating a `CelRuntime.Program` from a `CelAbstractSyntaxTree`:
232232

233233
```java
234-
CelRuntime celRuntime = CelRuntimeFactory.standardCelRuntimeBuilder().build();
234+
CelRuntime celRuntime = CelRuntimeFactory.plannerRuntimeBuilder().build();
235235
try {
236236
CelRuntime.Program program = celRuntime.createProgram(compileResult.getAst());
237237
return program.eval(

codelab/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static final CelCompiler CEL_COMPILER =
140140
// CelRuntime can also be initialized statically and cached just like the
141141
// compiler.
142142
private 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:
232232
Object 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
*/
316316
Object 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
*/
511511
Object 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
*/
591591
Object 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();
11381138
private static final CelRuntime CEL_RUNTIME =
1139-
CelRuntimeFactory.standardCelRuntimeBuilder()
1139+
CelRuntimeFactory.plannerRuntimeBuilder()
11401140
.addMessageTypes(AttributeContext.Request.getDescriptor())
11411141
.build();
11421142
```

codelab/src/main/codelab/Exercise3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class Exercise3 {
2828
private static final CelCompiler CEL_COMPILER =
2929
CelCompilerFactory.standardCelCompilerBuilder().setResultType(SimpleType.BOOL).build();
3030
private static final CelRuntime CEL_RUNTIME =
31-
CelRuntimeFactory.standardCelRuntimeBuilder().build();
31+
CelRuntimeFactory.plannerRuntimeBuilder().build();
3232

3333
/**
3434
* Compiles the given expression and evaluates it.

codelab/src/main/codelab/Exercise4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CelAbstractSyntaxTree compile(String expression) {
6363
*/
6464
Object eval(CelAbstractSyntaxTree ast, Map<String, ?> parameterValues) {
6565
CelRuntime celRuntime =
66-
CelRuntimeFactory.standardCelRuntimeBuilder()
66+
CelRuntimeFactory.plannerRuntimeBuilder()
6767
// Provide the custom `contains` function implementation here.
6868
.build();
6969

codelab/src/main/codelab/Exercise5.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ CelAbstractSyntaxTree compile(String expression) {
5555
* @throws IllegalArgumentException If the compiled expression in AST fails to evaluate.
5656
*/
5757
Object eval(CelAbstractSyntaxTree ast, Map<String, ?> parameterValues) {
58-
CelRuntime celRuntime = CelRuntimeFactory.standardCelRuntimeBuilder().build();
58+
CelRuntime celRuntime = CelRuntimeFactory.plannerRuntimeBuilder().build();
5959

6060
try {
6161
CelRuntime.Program program = celRuntime.createProgram(ast);

codelab/src/main/codelab/Exercise6.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CelAbstractSyntaxTree compile(String expression) {
5959
/** Evaluates the compiled AST with the user provided parameter values. */
6060
Object eval(CelAbstractSyntaxTree ast, Map<String, ?> parameterValues) {
6161
CelRuntime celRuntime =
62-
CelRuntimeFactory.standardCelRuntimeBuilder()
62+
CelRuntimeFactory.plannerRuntimeBuilder()
6363
.addMessageTypes(Request.getDescriptor())
6464
.build();
6565

codelab/src/main/codelab/Exercise7.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ CelAbstractSyntaxTree compile(String expression) {
5858
/** Evaluates the compiled AST with the user provided parameter values. */
5959
Object eval(CelAbstractSyntaxTree ast, Map<String, ?> parameterValues) {
6060
CelRuntime celRuntime =
61-
CelRuntimeFactory.standardCelRuntimeBuilder()
61+
CelRuntimeFactory.plannerRuntimeBuilder()
6262
.addMessageTypes(Request.getDescriptor())
6363
.build();
6464

codelab/src/main/codelab/Exercise8.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class Exercise8 {
4040
.addMessageTypes(AttributeContext.Request.getDescriptor())
4141
.build();
4242
private static final CelRuntime CEL_RUNTIME =
43-
CelRuntimeFactory.standardCelRuntimeBuilder()
43+
CelRuntimeFactory.plannerRuntimeBuilder()
4444
.addMessageTypes(AttributeContext.Request.getDescriptor())
4545
.build();
4646

codelab/src/main/codelab/Exercise9.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class Exercise9 {
5555
.addMessageTypes(AttributeContext.Request.getDescriptor())
5656
.build();
5757
private static final CelRuntime CEL_RUNTIME =
58-
CelRuntimeFactory.standardCelRuntimeBuilder()
58+
CelRuntimeFactory.plannerRuntimeBuilder()
5959
.addMessageTypes(AttributeContext.Request.getDescriptor())
6060
.build();
6161
private static final CelValidator CEL_VALIDATOR =

codelab/src/main/codelab/solutions/Exercise1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ CelAbstractSyntaxTree compile(String expression) {
7373
Object eval(CelAbstractSyntaxTree ast) {
7474
// Construct a CelRuntime instance
7575
// CelRuntime is immutable just like the compiler and can be moved to a static final member.
76-
CelRuntime celRuntime = CelRuntimeFactory.standardCelRuntimeBuilder().build();
76+
CelRuntime celRuntime = CelRuntimeFactory.plannerRuntimeBuilder().build();
7777

7878
try {
7979
// Plan the program

0 commit comments

Comments
 (0)