[
https://issues.apache.org/jira/browse/METRON-980?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16034511#comment-16034511
]
ASF GitHub Bot commented on METRON-980:
---------------------------------------
Github user justinleet commented on a diff in the pull request:
https://github.com/apache/metron/pull/606#discussion_r119832707
--- Diff:
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
---
@@ -634,6 +679,40 @@ public void testLogicalFunctions() throws Exception {
Assert.assertTrue(runPredicate("not(IN_SUBNET(ip_dst_addr,
'192.168.0.0/24'))", v-> variableMap.get(v)));
}
+ @Test
+ public void testShortCircuit_conditional() throws Exception {
+ Assert.assertEquals("foo", run("if true then 'foo' else
THROW('expression')", new HashMap<>()));
+ Assert.assertEquals("foo", run("true ? 'foo' : THROW('expression')",
new HashMap<>()));
+ Assert.assertEquals("foo", run("if false then THROW('exception') else
'foo'", new HashMap<>()));
+ Assert.assertEquals("foo", run("false ? THROW('exception') : 'foo'",
new HashMap<>()));
+ Assert.assertEquals(true, run("RET_TRUE(if true then 'foo' else
THROW('expression'))", new HashMap<>()));
+ Assert.assertEquals("foo", run("if true or (true or THROW('if
exception')) then 'foo' else THROW('expression')", new HashMap<>()));
+ Assert.assertEquals("foo", run("if true or (false or THROW('if
exception')) then 'foo' else THROW('expression')", new HashMap<>()));
+ Assert.assertEquals("foo", run("if NOT(true or (false or THROW('if
exception'))) then THROW('expression') else 'foo'", new HashMap<>()));
+ Assert.assertEquals("foo", run("if NOT('metron' in [ 'metron',
'metronicus'] ) then THROW('expression') else 'foo'", new HashMap<>()));
+ }
+
+ @Test
+ public void testShortCircuit_boolean() throws Exception {
+ Assert.assertTrue(runPredicate("'metron' in ['metron', 'metronicus',
'mortron'] or (true or THROW('exception'))", x -> null));
--- End diff --
Adding a case like:
`Assert.assertTrue(runPredicate("NOT(true) or THROW('exception'))", x ->
null));` doesn't parse and I would expect it to.
> Short circuit operations for Stellar
> ------------------------------------
>
> Key: METRON-980
> URL: https://issues.apache.org/jira/browse/METRON-980
> Project: Metron
> Issue Type: Improvement
> Reporter: Casey Stella
> Assignee: Casey Stella
>
> Stellar does not currently contain short circuit operations. In most
> languages, this is an important optimization, but for Stellar on Metron, this
> is a requirement due to the fact that some variables may be null legitimately
> and we cannot create multi-line conditionals or temporary variables at the
> moment.
> The short circuit operations supported:
> * short circuited `or` (e.g. true or FUNC(...) would never execute FUNC)
> * short circuited `and` (e.g. false and FUNC(...) would never execute FUNC)
> * short circuited if/then/else (e.g. if true then FUNC(...) else FUNC2(...)
> will never call FUNC2)
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)