mmiklavc 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_r276426806
 
 

 ##########
 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:
   What kind of type checking do you think we should add? The map should accept 
any types for keys and values, and the map argument itself will throw a 
ClassCastException if it's not actually a map. I tried to make the 
functionality pretty consistent with our examples, e.g. SET_ADD 
https://github.com/mmiklavc/metron/blob/a8628f1610a40cd0c790eb0b3caf6d2585db3018/metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/SetFunctions.java#L64

----------------------------------------------------------------
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

Reply via email to