ottobackwards commented on a change in pull request #1385: METRON-2071 Add
MAP_PUT and MAP_MERGE to Stellar
URL: https://github.com/apache/metron/pull/1385#discussion_r276488923
##########
File path:
metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MapFunctions.java
##########
@@ -82,4 +84,71 @@ public Object apply(List<Object> objects) {
return ret;
}
}
+
+ @Stellar(name = "PUT",
+ namespace = "MAP",
+ description = "Adds a key/value pair to a map",
+ params = {
+ "key - The key",
+ "value - The value",
+ "map - The map to perform the put on"
+ },
+ returns = "The original map modified with the key/value. If the map
argument is null, a new map will be created and returned that contains the
provided key and value - note: if the 'map' argument is null, only the returned
map will be non-null and contain the key/value."
+ )
+ public static class MapPut extends BaseStellarFunction {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object apply(List<Object> objects) {
+ if (objects.size() < 3) {
+ throw new IllegalArgumentException("Must pass a key, value, and map");
+ } else {
Review comment:
If you search for `instanceof` in stellar common you will see that we do
handle it, if only to return null at times. In many places.
We are certainly inconsistent on this point. My preference would be to
handle it, since we do not have explicitly typed parameters or parameter
checking
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services