You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metron.apache.org by jjmeyer0 <gi...@git.apache.org> on 2017/10/28 17:41:36 UTC

[GitHub] metron issue #814: METRON-1277 Add match statement to Stellar language

Github user jjmeyer0 commented on the issue:

    https://github.com/apache/metron/pull/814
  
    Also, I don't think there is an issue with the map function directly. It's actually an issue with the logical_expression `var1` and using/not using a `default` branch. It seems like the stack isn't properly being managed. For example things are being pushed (eg. when a logical_expr is just `var1`) when they shouldn't and popped  when they shouldn't be (eg. when there is no default?). I haven't pin pointed it directly yet, but I hope this helps somewhat. Below are a few example tests that I have created. 
    
    ```java
    // Here there is a null on the stack
    @Test
    @SuppressWarnings("unchecked")
    public void test1FailsWithMoreOnStack() {
        Assert.assertEquals("a",  run("match{ foo : 'a' }",
                new HashMap() {{
                    put("foo", true);
                }}));
    }
    ```
    
    // Here it's an empty stack when we expect 'a' i believe.
    ```java
    @Test
    @SuppressWarnings("unchecked")
    public void test1FailsEmptyStack() {
        Assert.assertEquals("a",  run("match{ foo == true : 'a' }",
                new HashMap() {{
                    put("foo", true);
                }}));
    }
    ```
    
    ```java
    // This is *not* properly handled
    @Test
    @SuppressWarnings("unchecked")
    public void test1Passes() {
        Assert.assertEquals("a",  run("match{ foo : 'a', default: 'b' }",
                new HashMap() {{
                    put("foo", true);
                }}));
    }
    ```
    
    ```java
    // This is properly handled
    @Test
    @SuppressWarnings("unchecked")
    public void test1Passes() {
        Assert.assertEquals("a",  run("match{ foo == true : 'a', default: 'b' }",
                new HashMap() {{
                    put("foo", true);
                }}));
    }
    ```
    
    ```java
    // Example where map works
    @Test
    @SuppressWarnings("unchecked")
    public void workingMatchWithMap() {
       Assert.assertEquals(Arrays.asList("OK", "HAHA"),  run("match{ foo > 100 : THROW('oops'), foo > 200 : THROW('oh no'), foo >= 50 : MAP(['ok', 'haha'], (a) -> TO_UPPER(a)), default: 'a' }",
              new HashMap() {{
                put("foo", 50);
              }}));
    }
    ```


---