Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Support CelOptions.enableComprehension(boolean) for feature parity with CEL-Cpp #484

Copy link
Copy link

Description

@sergiitk
Issue body actions

Feature request checklist

  • There are no issues that match the desired change
  • The change is large enough it can't be addressed with a simple Pull Request
  • If this is a bug, please file a Bug Report.

Change
To make CEL environment setup consistent across CEL implementations, I propose to add a runtime option equivalent to CEL-cpp InterpreterOptions.enable_comprehension to CEL-Java and CEL-Go (corresponding ticket cel-expr/cel-go#1050).

CelOptions.enableComprehension is true by default. Setting it to false will disable comprehension expressions (e.g. exists(), all() -- except has()). Under-the-hood it may simply call comprehensionMaxIterations(0) to disable comprehension expressions, and reset it to the default value to enable them.

Example

private static final CelRuntime CEL_RUNTIME = CelRuntimeFactory
    .standardCelRuntimeBuilder()
    .setOptions(CelOptions.current().enableComprehension(false).build())
    .build();
@Test
public void macros_comprehensionsDisabled() throws Exception {
  CelCompiler CEL_COMPILER = CelCompilerFactory.standardCelCompilerBuilder()
    .addVar("request", SimpleType.ANY)
    .setResultType(SimpleType.BOOL)
    .setStandardMacros(CelStandardMacro.STANDARD_MACROS)
    .build();

  String expr = "size(['foo', 'bar'].map(x, request[x])) == 2";
  CelRuntime.Program program = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());

  Map<String, ?> input = ImmutableMap.of("request", ImmutableMap.of("foo", "f", "bar", "b"));
  CelEvaluationException celErr = assertThrows(CelEvaluationException.class, () -> program.eval(input));

  assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.ITERATION_BUDGET_EXCEEDED);
}

Related
Internal ref: go/grpc-cel-integration

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.