metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [14/44] metron git commit: METRON-931: Stellar REDUCE incorrectly returns null for fewer than 3 items in list (mmiklavc) closes apache/incubator-metron#565
Date Thu, 01 Jun 2017 21:41:33 GMT
METRON-931: Stellar REDUCE incorrectly returns null for fewer than 3 items in list (mmiklavc)
closes apache/incubator-metron#565


Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/0d5fdf41
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/0d5fdf41
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/0d5fdf41

Branch: refs/heads/Metron_0.4.0
Commit: 0d5fdf419fdb2ad863eb531fa101f0f4ecae3497
Parents: 4662c77
Author: mmiklavc <michael.miklavcic@gmail.com>
Authored: Tue May 9 14:51:01 2017 -0600
Committer: Michael Miklavcic <michael.miklavcic@gmail.com>
Committed: Tue May 9 14:51:01 2017 -0600

----------------------------------------------------------------------
 .../dsl/functions/FunctionalFunctions.java      |  2 +-
 .../dsl/functions/FunctionalFunctionsTest.java  | 43 +++++++++++++++++++-
 2 files changed, 42 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metron/blob/0d5fdf41/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/FunctionalFunctions.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/FunctionalFunctions.java
b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/FunctionalFunctions.java
index 0f39d1d..40e8863 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/FunctionalFunctions.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/FunctionalFunctions.java
@@ -94,7 +94,7 @@ public class FunctionalFunctions {
     @Override
     public Object apply(List<Object> args) {
       List<Object> input = (List<Object>) args.get(0);
-      if(input == null || input.size() < 3) {
+      if(input == null || args.size() < 3) {
         return null;
       }
       LambdaExpression expression = (LambdaExpression) args.get(1);

http://git-wip-us.apache.org/repos/asf/metron/blob/0d5fdf41/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
b/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
index 2e1859e..bd70a33 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/FunctionalFunctionsTest.java
@@ -20,6 +20,7 @@ package org.apache.metron.common.dsl.functions;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import org.hamcrest.CoreMatchers;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -205,8 +206,8 @@ public class FunctionalFunctionsTest {
 
   @Test
   public void testReduce() {
-    for (String expr : ImmutableList.of("REDUCE([ 1, 2, 3], (x, y) -> x + y , 0 )"
-                                       ,"REDUCE([ foo, bar, 3], (x, y) -> x + y , 0 )"
+    for (String expr : ImmutableList.of("REDUCE([ 1, 2, 3 ], (x, y) -> x + y , 0 )"
+                                       ,"REDUCE([ foo, bar, 3 ], (x, y) -> x + y , 0 )"
                                        )
         )
     {
@@ -218,6 +219,31 @@ public class FunctionalFunctionsTest {
   }
 
   @Test
+  public void testReduce_on_various_list_sizes() {
+    {
+      String expr = "REDUCE([ 1, 2, 3, 4 ], (x, y) -> x + y , 0 )";
+      Object o = run(expr, ImmutableMap.of());
+      Assert.assertTrue(o instanceof Number);
+      Number result = (Number) o;
+      Assert.assertEquals(10, result.intValue());
+    }
+    {
+      String expr = "REDUCE([ 1, 2 ], (x, y) -> x + y , 0 )";
+      Object o = run(expr, ImmutableMap.of());
+      Assert.assertTrue(o instanceof Number);
+      Number result = (Number) o;
+      Assert.assertEquals(3, result.intValue());
+    }
+    {
+      String expr = "REDUCE([ 1 ], (x, y) -> x + y , 0 )";
+      Object o = run(expr, ImmutableMap.of());
+      Assert.assertTrue(o instanceof Number);
+      Number result = (Number) o;
+      Assert.assertEquals(1, result.intValue());
+    }
+  }
+
+  @Test
   public void testReduce_NonNumeric() {
     for (String expr : ImmutableList.of("REDUCE([ 'foo', 'bar', 'grok'], (x, y) -> LIST_ADD(x,
y), [] )"
                                        )
@@ -232,4 +258,17 @@ public class FunctionalFunctionsTest {
       Assert.assertEquals("grok", result.get(2));
     }
   }
+
+  @Test
+  public void testReduce_returns_null_when_less_than_3_args() {
+    {
+      String expr = "REDUCE([ 1, 2, 3 ], (x, y) -> LIST_ADD(x, y))";
+      Assert.assertThat(run(expr, ImmutableMap.of()), CoreMatchers.equalTo(null));
+    }
+    {
+      String expr = "REDUCE([ 1, 2, 3 ])";
+      Assert.assertThat(run(expr, ImmutableMap.of()), CoreMatchers.equalTo(null));
+    }
+  }
+
 }


Mime
View raw message