metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickwallen <...@git.apache.org>
Subject [GitHub] incubator-metron pull request #207: METRON-362: Unify the Stellar Languages
Date Thu, 11 Aug 2016 13:50:40 GMT
Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/207#discussion_r74425090
  
    --- Diff: metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/StellarCompiler.java
---
    @@ -16,276 +16,224 @@
      * limitations under the License.
      */
     
    -package org.apache.metron.common.query;
    +package org.apache.metron.common.stellar;
     
     import com.google.common.base.Joiner;
     import com.google.common.collect.ImmutableSet;
     import org.apache.metron.common.dsl.*;
    -import org.apache.metron.common.query.generated.PredicateBaseListener;
    -import org.apache.metron.common.query.generated.PredicateParser;
    +import org.apache.metron.common.stellar.generated.StellarBaseListener;
    +import org.apache.metron.common.stellar.generated.StellarParser;
    +import org.apache.metron.common.utils.ConversionUtils;
     
     import java.util.*;
     import java.util.function.Function;
    -import java.util.function.Predicate;
     
    -class QueryCompiler extends PredicateBaseListener {
    +public class StellarCompiler extends StellarBaseListener {
       private VariableResolver resolver = null;
       private Stack<Token> tokenStack = new Stack<>();
    -
    -  public QueryCompiler(VariableResolver resolver) {
    +  public StellarCompiler(VariableResolver resolver) {
         this.resolver = resolver;
       }
     
       @Override
    -  public void enterSingle_rule(org.apache.metron.common.query.generated.PredicateParser.Single_ruleContext
ctx) {
    +  public void enterTransformation(StellarParser.TransformationContext ctx) {
         tokenStack.clear();
       }
     
    -  @Override
    -  public void exitSingle_rule(org.apache.metron.common.query.generated.PredicateParser.Single_ruleContext
ctx) {
    -  }
    +  private boolean handleIn(Token<?> left, Token<?> right) {
    +    Object key = null;
     
    -  @Override
    -  public void exitLogicalExpressionAnd(PredicateParser.LogicalExpressionAndContext ctx)
{
    -    Token<?> left = popStack();
    -    Token<?> right = popStack();
    -    tokenStack.push(new Token<>(booleanOp(left, right, (l, r) -> l &&
r, "&&"), Boolean.class));
    -  }
    +    Set<Object> set = null;
    +    if(left.getValue() instanceof Collection) {
    +      set = new HashSet<>((List<Object>) left.getValue());
    +    }
    +    else if(left.getValue() != null) {
    +      set = ImmutableSet.of(left.getValue());
    +    }
    +    else {
    +      set = new HashSet<>();
    +    }
     
    -  @Override
    -  public void exitLogicalExpressionOr(PredicateParser.LogicalExpressionOrContext ctx)
{
    -    Token<?> left = popStack();
    -    Token<?> right = popStack();
     
    -    tokenStack.push(new Token<>(booleanOp(left, right, (l, r) -> l || r, "||"),
Boolean.class));
    +    key = right.getValue();
    +    if(key == null || set.isEmpty()) {
    +      return false;
    +    }
    +    return set.contains(key);
       }
     
    -  private boolean booleanOp(Token<?> left, Token<?> right, BooleanOp op,
String opName)
    -  {
    -    if(left.getUnderlyingType().equals(right.getUnderlyingType()) && left.getUnderlyingType().equals(Boolean.class))
{
    -      Boolean l = (Boolean) left.getValue();
    -      Boolean r = (Boolean) right.getValue();
    -      if(l == null || r == null) {
    -        throw new ParseException("Unable to operate on " + left.getValue()  + " " + opName
+ " " + right.getValue() + ", null value");
    -      }
    -      return op.op(l, r);
    +  private Double getDouble(Token<?> token) {
    +    Number n = (Number)token.getValue();
    +    if(n == null) {
    +      return 0d;
         }
         else {
    -      throw new ParseException("Unable to operate on " + left.getValue()  + " " + opName
+ " " + right.getValue() + ", bad types");
    +      return n.doubleValue();
         }
       }
     
     
    -  @Override
    -  public void exitLogicalConst(PredicateParser.LogicalConstContext ctx) {
    -    Boolean b = null;
    -    switch(ctx.getText().toUpperCase()) {
    -      case "TRUE":
    -        b = true;
    -        break;
    -      case "FALSE":
    -        b = false;
    -        break;
    -      default:
    -        throw new ParseException("Unable to process " + ctx.getText() + " as a boolean
constant");
    -    }
    -    tokenStack.push(new Token<>(b, Boolean.class));
    +
    +
    +  /*@Override
    +  public void enterArithExpr_plus(StellarParser.ArithExpr_plusContext ctx) {
    --- End diff --
    
    Assuming we don't need this since it is commented out?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message