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

Add aggregate semantics to Policy Compiler#1052

Open
copybara-service[bot] wants to merge 1 commit into
maincel-expr/cel-java:mainfrom
test_913930387cel-expr/cel-java:test_913930387Copy head branch name to clipboard
Open

Add aggregate semantics to Policy Compiler#1052
copybara-service[bot] wants to merge 1 commit into
maincel-expr/cel-java:mainfrom
test_913930387cel-expr/cel-java:test_913930387Copy head branch name to clipboard

Conversation

@copybara-service

@copybara-service copybara-service Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

Add aggregate semantics to Policy Compiler

Aggregate walks through all matching rules (including nested ones) and appends them into a list:

rule:
  semantics: aggregate
  match:
    - condition: "true"
      output: "'FOO'"
    - condition: "true"
      output: "'BAR'"

# Output: ['FOO','BAR']

Few noteworthy design decisions below. All examples assume all conditions matched:

  1. For usability reasons, subrules under an aggregate ancestor will always have their lists flattened:
name: aggregate_flat_flattening_example
rule:
  semantics: aggregate
  match:
    - rule:
        semantics: first_match
        match:
          - condition: "resource.is_admin == true"
            rule:
              semantics: aggregate
              match:
                - condition: "resource.has_standard_pii == true"
                  output: "'GDPR_STANDARD'"    
                - condition: "resource.is_b2c == true"
                  output: "'EU_B2C_NOTICE'"     
    - condition: "true"
      output: "'FALLBACK'"

# Output: ['GDPR_STANDARD', 'EU_B2C_NOTICE', 'FALLBACK']
  1. Base case of an aggregate rule is an empty list. Nested conditional rules within an aggregate rule which outputs optional.none() are pruned (except in cases where policy output explicitly emits an optional.none()):
name: optional_pruning_example
rule:
  semantics: aggregate
  match:
    - rule:
        semantics: first_match
        match:
          - condition: "1 == 2"
            output: "'EU_NOTICE'"
    - condition: "true"
      output: "'ALWAYS'"

# Output: ['ALWAYS']
name: explicit_optional_none_example
rule:
  semantics: aggregate
  match:
    - rule:
        semantics: first_match
        match:
          - condition: "resource.is_b2c == true"
            output: "optional.none()"   # Explicitly authored by user

    - condition: "true"
      output: "optional.of('ALWAYS')"

# Output: [optional.none(), optional.of('ALWAYS')]

@copybara-service copybara-service Bot force-pushed the test_913930387 branch 4 times, most recently from a194d42 to 634780b Compare May 12, 2026 21:10
@copybara-service copybara-service Bot changed the title Add aggregate semantic to Policy Compiler Add aggregate semantics to Policy Compiler May 12, 2026
@copybara-service copybara-service Bot force-pushed the test_913930387 branch 11 times, most recently from 6714afc to 380bcf3 Compare May 13, 2026 23:37
Aggregate walks through all matching rules (including nested ones) and appends them into a list:

```yaml
rule:
  semantics: aggregate
  match:
    - condition: "true"
      output: "'FOO'"
    - condition: "true"
      output: "'BAR'"

# Output: ['FOO','BAR']
```

Few noteworthy design decisions below. All examples assume all conditions matched:

1. For usability reasons, subrules under an aggregate ancestor will always have their **lists flattened**:

```YAML
name: aggregate_flat_flattening_example
rule:
  semantics: aggregate
  match:
    - rule:
        semantics: first_match
        match:
          - condition: "resource.is_admin == true"
            rule:
              semantics: aggregate
              match:
                - condition: "resource.has_standard_pii == true"
                  output: "'GDPR_STANDARD'"
                - condition: "resource.is_b2c == true"
                  output: "'EU_B2C_NOTICE'"
    - condition: "true"
      output: "'FALLBACK'"

# Output: ['GDPR_STANDARD', 'EU_B2C_NOTICE', 'FALLBACK']
```

2. Base case of an aggregate rule is an empty list. Nested conditional rules within an aggregate rule which outputs `optional.none()` are pruned (except in cases where policy output explicitly emits an `optional.none()`):

```YAML
name: optional_pruning_example
rule:
  semantics: aggregate
  match:
    - rule:
        semantics: first_match
        match:
          - condition: "1 == 2"
            output: "'EU_NOTICE'"
    - condition: "true"
      output: "'ALWAYS'"

# Output: ['ALWAYS']
```

```YAML
name: explicit_optional_none_example
rule:
  semantics: aggregate
  match:
    - rule:
        semantics: first_match
        match:
          - condition: "resource.is_b2c == true"
            output: "optional.none()"   # Explicitly authored by user

    - condition: "true"
      output: "optional.of('ALWAYS')"

# Output: [optional.none(), optional.of('ALWAYS')]
```

PiperOrigin-RevId: 913930387
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

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