This is an automated email from the ASF dual-hosted git repository. mmiklavcic pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/metron.git
The following commit(s) were added to refs/heads/master by this push: new 9b70adf METRON-2123 Expand Stellar JOIN to work on all Iterables (mmiklavc) closes apache/metron#1416 9b70adf is described below commit 9b70adf1d7f716c4a301af10c6726c40ecb1f3dc Author: mmiklavc <michael.miklav...@gmail.com> AuthorDate: Fri May 24 11:51:47 2019 -0600 METRON-2123 Expand Stellar JOIN to work on all Iterables (mmiklavc) closes apache/metron#1416 --- metron-stellar/stellar-common/README.md | 4 ++-- .../stellar/dsl/functions/StringFunctions.java | 20 +++++++++----------- .../stellar/dsl/functions/BasicStellarTest.java | 2 ++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/metron-stellar/stellar-common/README.md b/metron-stellar/stellar-common/README.md index 551a52a..5e48b1c 100644 --- a/metron-stellar/stellar-common/README.md +++ b/metron-stellar/stellar-common/README.md @@ -702,9 +702,9 @@ Where: * Returns: True if the string is a valid URL and false if otherwise. ### `JOIN` - * Description: Joins the components in the list of strings with the specified delimiter. + * Description: Joins the non-null items in the iterable as strings with the specified delimiter. Null items are dropped. * Input: - * list - List of strings + * iterable - Java iterable (e.g. List, LinkedHashSet, etc.) of items treated as strings * delim - String delimiter * Returns: String diff --git a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java index 5019852..89e5f61 100644 --- a/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java +++ b/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java @@ -19,22 +19,20 @@ package org.apache.metron.stellar.dsl.functions; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Joiner; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; -import org.apache.commons.lang3.StringUtils; -import org.apache.metron.stellar.common.utils.JSONUtils; -import org.apache.metron.stellar.dsl.BaseStellarFunction; -import org.apache.metron.stellar.dsl.ParseException; -import org.apache.metron.stellar.dsl.Stellar; -import org.apache.metron.stellar.common.utils.ConversionUtils; - import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.apache.metron.stellar.common.utils.ConversionUtils; +import org.apache.metron.stellar.common.utils.JSONUtils; +import org.apache.metron.stellar.dsl.BaseStellarFunction; +import org.apache.metron.stellar.dsl.ParseException; +import org.apache.metron.stellar.dsl.Stellar; public class StringFunctions { @@ -133,15 +131,15 @@ public class StringFunctions { } @Stellar( name="JOIN" - , description="Joins the components in the list of strings with the specified delimiter." - , params = { "list - List of strings", "delim - String delimiter"} + , description="Joins the non-null items in the iterable as strings with the specified delimiter. Null items are dropped." + , params = { "iterable - Java iterable (e.g. List, LinkedHashSet, etc.) of items treated as strings", "delim - String delimiter"} , returns = "String" ) public static class JoinFunction extends BaseStellarFunction { @Override @SuppressWarnings("unchecked") public Object apply(List<Object> args) { - List<Object> arg1 = (List<Object>) args.get(0); + Iterable<Object> arg1 = (Iterable<Object>) args.get(0); String delim = (String) args.get(1); return Joiner.on(delim).join(Iterables.filter(arg1, x -> x != null)); } diff --git a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java index 4b64f72..c2f5ca0 100644 --- a/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java +++ b/metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java @@ -620,6 +620,8 @@ public class BasicStellarTest { public void testJoin() { String query = "JOIN( [ TO_UPPER(TRIM(foo)), 'bar' ], ',')"; Assert.assertEquals("CASEY,bar", run(query, ImmutableMap.of("foo", "casey "))); + query = "JOIN( SET_INIT( [ 1, 2, 'buckle', 'my', 'shoe', 3 ] ), ',')"; + Assert.assertEquals("1,2,buckle,my,shoe,3", run(query, new HashMap<>())); } @Test