[GitHub] incubator-metron pull request #293: METRON-473 Add LENGTH() To Stellar

2016-10-06 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/293#discussion_r82259618
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -30,9 +30,7 @@
 import org.reflections.Reflections;
 import org.reflections.util.ConfigurationBuilder;
 
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
+import java.util.*;
--- End diff --

I did not actually change this on purpose, I'll fix


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-metron pull request #293: METRON-473 Add LENGTH() To Stellar

2016-10-06 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/293#discussion_r82218813
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -285,6 +285,18 @@ public void testHappyPath() {
   }
 
   @Test
+  public void testLength(){
+String query = "LENGTH(foo)";
+Assert.assertEquals(5, run(query,ImmutableMap.of("foo","abcde")));
+  }
+
+  @Test
--- End diff --

I will fix - see my comment above about how to test


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-metron pull request #293: METRON-473 Add LENGTH() To Stellar

2016-10-06 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/293#discussion_r82218691
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -285,6 +285,18 @@ public void testHappyPath() {
   }
 
   @Test
--- End diff --

So, I was going to make a test passing in NULL, but the Immutable map will 
not take nulls, can you clarify how you would test this?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-metron pull request #293: METRON-473 Add LENGTH() To Stellar

2016-10-06 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/293#discussion_r82218396
  
--- Diff: 
metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
 ---
@@ -222,4 +222,16 @@ public Object apply(List args) {
   return null;
 }
   }
+
+  @Stellar( name="LENGTH"
+  , description = "Returns the length of a string"
+  , params = { "input - String" }
+  , returns = "String"
--- End diff --

No - I need to fix that.  I started with the TO_UPPER def. to make sure I 
got it right and need to change that.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-metron pull request #293: METRON-473 Add LENGTH() To Stellar

2016-10-06 Thread nickwallen
Github user nickwallen commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/293#discussion_r82217916
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -285,6 +285,18 @@ public void testHappyPath() {
   }
 
   @Test
+  public void testLength(){
+String query = "LENGTH(foo)";
+Assert.assertEquals(5, run(query,ImmutableMap.of("foo","abcde")));
+  }
+
+  @Test
--- End diff --

If I mistakenly call `LENGTH()` with no argument, then I get an 
`IndexOutOfBoundsException`.  And this is not unique to the `LENGTH` function.  
There are a number of other Stellar functions that do the same.

This may be confusing to a user of Stellar who is not familiar with the 
underlying implementation.  "IndexOutOfBounds? What the heck does that mean?"  

I wonder if it makes sense to handle this in a standard way within Stellar. 
 Ideally we would get something along the lines of "LENGTH: Missing first 
argument 'input'.  Expected 'String'".  

I bring this up only as a discussion point for future work.  This PR does 
not necessarily have to address this situation.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-metron pull request #293: METRON-473 Add LENGTH() To Stellar

2016-10-06 Thread nickwallen
Github user nickwallen commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/293#discussion_r82215514
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -285,6 +285,18 @@ public void testHappyPath() {
   }
 
   @Test
--- End diff --

I would add one more test that validates the behavior when you call LENGTH 
on an undefined variable; `LENGTH(foo)` when there is no variable `foo`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-metron pull request #293: METRON-473 Add LENGTH() To Stellar

2016-10-06 Thread nickwallen
Github user nickwallen commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/293#discussion_r82214084
  
--- Diff: 
metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
 ---
@@ -222,4 +222,16 @@ public Object apply(List args) {
   return null;
 }
   }
+
+  @Stellar( name="LENGTH"
+  , description = "Returns the length of a string"
+  , params = { "input - String" }
+  , returns = "String"
--- End diff --

Probably need to change`returns = "String"` to indicate that it returns an 
Integer which is the length of the String.  However you want to say that is 
fine, but it does not actually return a String.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-metron pull request #293: METRON-473 Add LENGTH() To Stellar

2016-10-05 Thread ottobackwards
GitHub user ottobackwards opened a pull request:

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

METRON-473 Add LENGTH() To Stellar

Add LENGTH to Stellar string functions and unit tests.

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

$ git pull https://github.com/ottobackwards/incubator-metron METRON-473

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

https://github.com/apache/incubator-metron/pull/293.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 #293


commit 7aaa5d0cd08ae0861601ff2a763f45c71d70dbce
Author: Otto Fowler 
Date:   2016-10-05T14:23:50Z

METRON-473 Add LENGTH() function for getting the length of strings to 
Stellar dsl functions




---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---