-
Notifications
You must be signed in to change notification settings - Fork 143
[plan][runtime][java] Add CEL Action condition filtering #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rosemarYuan
wants to merge
4
commits into
apache:main
Choose a base branch
from
rosemarYuan:pr2/java-cel-implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,289
−66
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1398c4e
[api][plan][runtime][python] Implement CEL-based @Action trigger cond…
rosemarYuan 9d664e9
[plan][runtime][e2e][test] Add trigger-condition tests and conformanc…
rosemarYuan cda3875
[dist] Bundle dev.cel license entries
rosemarYuan e181859
[runtime] Trim CEL trigger activation to referenced merged keys
rosemarYuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
dist/src/main/resources/META-INF/licenses/LICENSE.antlr4-runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| Copyright (c) 2012-2022 The ANTLR Project. All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions | ||
| are met: | ||
|
|
||
| 1. Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
|
|
||
| 2. Redistributions in binary form must reproduce the above copyright | ||
| notice, this list of conditions and the following disclaimer in the | ||
| documentation and/or other materials provided with the distribution. | ||
|
|
||
| 3. Neither name of copyright holders nor the names of its contributors | ||
| may be used to endorse or promote products derived from this software | ||
| without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR | ||
| CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| This is a work derived from Russ Cox's RE2 in Go, whose license | ||
| http://golang.org/LICENSE is as follows: | ||
|
|
||
| Copyright (c) 2009 The Go Authors. All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are | ||
| met: | ||
|
|
||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
|
|
||
| * Redistributions in binary form must reproduce the above copyright | ||
| notice, this list of conditions and the following disclaimer in | ||
| the documentation and/or other materials provided with the | ||
| distribution. | ||
|
|
||
| * Neither the name of Google Inc. nor the names of its contributors | ||
| may be used to endorse or promote products derived from this | ||
| software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../test/java/org/apache/flink/agents/integration/test/ConditionTriggerIntegrationAgent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.flink.agents.integration.test; | ||
|
|
||
| import org.apache.flink.agents.api.Event; | ||
| import org.apache.flink.agents.api.EventType; | ||
| import org.apache.flink.agents.api.InputEvent; | ||
| import org.apache.flink.agents.api.OutputEvent; | ||
| import org.apache.flink.agents.api.agents.Agent; | ||
| import org.apache.flink.agents.api.annotation.Action; | ||
| import org.apache.flink.agents.api.context.RunnerContext; | ||
|
|
||
| /** | ||
| * Agent exercising {@code @Action} trigger conditions end-to-end: one action fires on every input | ||
| * event, one is gated by a condition expression on the input value, one uses a {@code | ||
| * has()}-guarded expression, and one re-emits each input as a custom dotted/hyphenated event type | ||
| * consumed by a quoted-type-name action routed via the type index. | ||
| */ | ||
| public class ConditionTriggerIntegrationAgent extends Agent { | ||
|
|
||
| @Action(EventType.InputEvent) | ||
| public static void onAnyInput(Event event, RunnerContext ctx) { | ||
| Object input = InputEvent.fromEvent(event).getInput(); | ||
| ctx.sendEvent(new OutputEvent("all:" + input)); | ||
| } | ||
|
|
||
| @Action("type == EventType.InputEvent && input > 5") | ||
| public static void onHighInput(Event event, RunnerContext ctx) { | ||
| Object input = InputEvent.fromEvent(event).getInput(); | ||
| ctx.sendEvent(new OutputEvent("high:" + input)); | ||
| } | ||
|
|
||
| @Action("has(input) && input > 5") | ||
| public static void onGuardedHighInput(Event event, RunnerContext ctx) { | ||
| Object input = InputEvent.fromEvent(event).getInput(); | ||
| ctx.sendEvent(new OutputEvent("guard:" + input)); | ||
| } | ||
|
|
||
| /** Re-emits every input as a custom dotted/hyphenated event type. */ | ||
| @Action(EventType.InputEvent) | ||
| public static void reEmitAsCustomType(Event event, RunnerContext ctx) { | ||
| Object input = InputEvent.fromEvent(event).getInput(); | ||
| Event custom = new Event("com.example.order-scored"); | ||
| custom.setAttr("v", input); | ||
| ctx.sendEvent(custom); | ||
| } | ||
|
|
||
| /** Quoted complex type name: routed via the type index, no condition evaluation. */ | ||
| @Action("'com.example.order-scored'") | ||
| public static void onQuotedCustomType(Event event, RunnerContext ctx) { | ||
| ctx.sendEvent(new OutputEvent("quoted:" + event.getAttr("v"))); | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
...c/test/java/org/apache/flink/agents/integration/test/ConditionTriggerIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.flink.agents.integration.test; | ||
|
|
||
| import org.apache.flink.agents.api.AgentsExecutionEnvironment; | ||
| import org.apache.flink.api.java.functions.KeySelector; | ||
| import org.apache.flink.streaming.api.datastream.DataStream; | ||
| import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; | ||
| import org.apache.flink.util.CloseableIterator; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * End-to-end test for {@code @Action} trigger conditions in a full Flink pipeline: an unconditioned | ||
| * action must fire for every input record, condition-gated actions must fire only for records | ||
| * matching their expression, and a second typed action exercises typed fan-out plus | ||
| * quoted-type-name routing via the type index. | ||
| */ | ||
| public class ConditionTriggerIntegrationTest { | ||
|
|
||
| @Test | ||
| public void testConditionGatedActionsFireSelectively() throws Exception { | ||
| StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
| env.setParallelism(1); | ||
|
|
||
| // Two records above the threshold (9, 7), two below (2, 4). | ||
| DataStream<Integer> inputStream = env.fromElements(2, 9, 4, 7); | ||
|
|
||
| AgentsExecutionEnvironment agentsEnv = | ||
| AgentsExecutionEnvironment.getExecutionEnvironment(env); | ||
|
|
||
| DataStream<Object> outputStream = | ||
| agentsEnv | ||
| .fromDataStream(inputStream, (KeySelector<Integer, Integer>) value -> value) | ||
| .apply(new ConditionTriggerIntegrationAgent()) | ||
| .toDataStream(); | ||
|
|
||
| CloseableIterator<Object> results = outputStream.collectAsync(); | ||
| agentsEnv.execute(); | ||
|
|
||
| List<String> outputs = new ArrayList<>(); | ||
| while (results.hasNext()) { | ||
| outputs.add((String) results.next()); | ||
| } | ||
| results.close(); | ||
|
|
||
| assertThat(outputs.stream().filter(o -> o.startsWith("all:"))) | ||
| .as("unconditioned action must fire for every record") | ||
| .containsExactlyInAnyOrder("all:2", "all:9", "all:4", "all:7"); | ||
| assertThat(outputs.stream().filter(o -> o.startsWith("high:"))) | ||
| .as("condition-gated action must fire only for records > 5") | ||
| .containsExactlyInAnyOrder("high:9", "high:7"); | ||
| assertThat(outputs.stream().filter(o -> o.startsWith("guard:"))) | ||
| .as("has()-guarded action must fire only for records > 5") | ||
| .containsExactlyInAnyOrder("guard:9", "guard:7"); | ||
| assertThat(outputs.stream().filter(o -> o.startsWith("quoted:"))) | ||
| .as("quoted dotted/hyphenated type must route via the type index") | ||
| .containsExactlyInAnyOrder("quoted:2", "quoted:9", "quoted:4", "quoted:7"); | ||
| assertThat(outputs).hasSize(12); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dev.cel:common:0.12.0
dev.cel:compiler:0.12.0
dev.cel:runtime:0.12.0
dev.cel:v1alpha1:0.12.0