[ 
https://issues.apache.org/jira/browse/METRON-624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15773734#comment-15773734
 ] 

ASF GitHub Bot commented on METRON-624:
---------------------------------------

GitHub user jjmeyer0 opened a pull request:

    https://github.com/apache/incubator-metron/pull/404

    METRON-624: Updated Comparison/Equality Evaluations in Stellar

    1. General cleanup in Stellar.g4
    - Refactored the grammar to consistently use fragments instead of inlining 
things.
    
    2. Updated the way Stellar transformations were validated
    - Previously Stellar parsed/evaluated the transformation to validate it. In 
certain circumstances this would cause failures. For instances, all variables 
would be resolved to null which would cause an error to be thrown when 
evaluating transformations such as: '1 < foo', '1 < null'. Both of these 
statements are syntactically valid.
    - Now the validation just checks whether the Stellar transformation is 
syntactically valid. It will not send the transformation through the listener 
as it once did. It will not validate that variables are defined. It will not 
validate functions are defined.
    
    3. Updated comparison/equality expression evaluation
    - Number 2 was required in order to update the comparison/equality 
evaluation.
    - Now statements such as 1 == '1' will return false.
    - When comparing numerical values, the standard promotion rules apply 
(http://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.6.2).
    - When comparing non-numeric types, compareTo method is used.
    - When either side is null then '==' and '!=' are used. For all other 
comparison operators null value would throw exception.
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jjmeyer0/incubator-metron METRON-624

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-metron/pull/404.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #404
    
----
commit c1a9a25615f2a4bc09f6c0f2eb0b8b127d1ea2ef
Author: JJ <[email protected]>
Date:   2016-12-23T18:23:18Z

    METRON-624: Updated Stellar to handle comparison/equality properly. These 
are broken up into a few categories: null comparisons, numerical comparisons, 
others types that can be compared, otherwise exception occurs.

commit c0cc0bdcdaa16cbd1d19203dda722316a6a4ffb9
Author: JJ <[email protected]>
Date:   2016-12-23T21:02:35Z

    Updated the way a Stellar transformation is validated. Before this update 
the listener was used to validate the Stellar transformation expression. This 
would cause issues because the variable map wasn't be passed in causing all 
variables to resolve to null which would potentially cause a failure. 
Particularly when trying to validate expressions such as 'null < 1' which is 
syntactically valid, but semantically may not be. This commit updates the 
validation to say whether the rule is syntactically valid. It does not try to 
interpret anything. It just says whether the rule conforms to the Stellar 
grammar or not.

----


> Comparison Operators Evaluate Incorrectly
> -----------------------------------------
>
>                 Key: METRON-624
>                 URL: https://issues.apache.org/jira/browse/METRON-624
>             Project: Metron
>          Issue Type: Bug
>            Reporter: Josh Meyer
>              Labels: stellar
>
> Currently there is an issue with the way Stellar interprets comparison 
> expressions. Currently it only compares numbers when both sides are numbers 
> otherwise it converts both sides of the expression to a value and then 
> compares them. Also, when looking at numbers it always gets double values to 
> compare.
> Below is an example of a failing test that should pass.
> {code:theme=FadeToGrey|linenumbers=true|language=java|firstline=0001|collapse=false}
>   @Test
>   public void compareNumberAndStringWithSameValueShouldFail() throws 
> Exception {
>     final Map<String, String> variableMap = new HashMap<>();
>     assertFalse(runPredicate("1 == '1'", variableMap::get));
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to