Github user cestella commented on a diff in the pull request: https://github.com/apache/metron/pull/736#discussion_r137808595 --- Diff: metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/ProfilerFunctions.java --- @@ -131,50 +133,99 @@ public boolean isInitialized() { @Override public Object apply(List<Object> args, Context context) throws ParseException { - // user must provide the message as a string - String arg0 = Util.getArg(0, String.class, args); - if(arg0 == null) { - throw new IllegalArgumentException(format("expected string, found null")); + // the use can pass in one or more messages in a few different forms + Object arg0 = Util.getArg(0, Object.class, args); + List<JSONObject> messages = getMessages(arg0); + + // user must provide the stand alone profiler + StandAloneProfiler profiler = Util.getArg(1, StandAloneProfiler.class, args); + try { + for (JSONObject message : messages) { + profiler.apply(message); + } + + } catch (ExecutionException e) { + throw new IllegalArgumentException(format("Failed to apply message; error=%s", e.getMessage()), e); + } + + return profiler; + } + + /** + * Gets a message or messages from the function arguments. + * + * @param arg The function argument containing the message(s). + * @return A list of messages + */ + private List<JSONObject> getMessages(Object arg) { + List<JSONObject> messages; + + if (arg instanceof String) { + messages = getMessagesFromString((String) arg); + + } else if (arg instanceof List) { + messages = getMessagesFromList((List<String>) arg); + + } else if (arg instanceof JSONObject) { + messages = Collections.singletonList((JSONObject) arg); + + } else { + throw new IllegalArgumentException(format("invalid message: found '%s', expected String, List, or JSONObject", + ClassUtils.getShortClassName(arg, "null"))); } - // there could be one or more messages + return messages; + } + + /** + * Gets a message or messages from a List + * + * @param listOfStrings The function argument is a List of Strings. + * @return A list of messages. + */ + private List<JSONObject> getMessagesFromList(List<String> listOfStrings) { --- End diff -- Just a very small nit, but could we make that an iterable instead of a List since that's all you really need? We now have SETs in stellar too and I think we may end up creating lazy iterable transformation functions too. (e.g. `PROFILE_APPLY( LAZY_MAP( [ msg1, msg2 ], m -> REGEX_APPLY(...., m))`
---