[
https://issues.apache.org/jira/browse/METRON-980?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16039973#comment-16039973
]
ASF GitHub Bot commented on METRON-980:
---------------------------------------
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/606#discussion_r119960003
--- Diff:
metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/StellarCompiler.java
---
@@ -76,14 +92,80 @@ public Expression(Deque<Token<?>> tokenDeque) {
public Object apply(ExpressionState state) {
Deque<Token<?>> instanceDeque = new ArrayDeque<>();
- for(Iterator<Token<?>> it =
getTokenDeque().descendingIterator();it.hasNext();) {
- Token<?> token = it.next();
- if(token.getUnderlyingType() == DeferredFunction.class) {
- DeferredFunction func = (DeferredFunction) token.getValue();
- func.apply(instanceDeque, state);
- }
- else {
- instanceDeque.push(token);
+ {
+ boolean skipElse = false;
+ Token<?> token = null;
+ for (Iterator<Token<?>> it = getTokenDeque().descendingIterator();
it.hasNext(); ) {
+ token = it.next();
+ //if we've skipped an else previously, then we need to skip the
deferred tokens associated with the else.
+ if(skipElse && token.getUnderlyingType() == ElseExpr.class) {
+ while(it.hasNext()) {
+ token = it.next();
+ if(token.getUnderlyingType() == EndConditional.class) {
+ break;
+ }
--- End diff --
So I admit I don't fully understand the token deque, but will this work
with nested if/else statements? eg of form
"if A1 then B1 else (if A2 then B2 else C2)"? If A1 is true we'll want to
skip all of the level-1 else clause, not just C2.
> 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)