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_r275826259
##########
File path:
metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/BasicStellarTest.java
##########
@@ -641,6 +645,74 @@ public void testMapGet() {
);
}
+ @Test
+ public void testMapPut() {
+ Map vars = ImmutableMap.of("mymap", new HashMap<String, String>());
+ String query = "MAP_PUT('foo','bar',mymap)";
+ assertThat(run(query, vars), instanceOf(Map.class));
+ query = "MAP_GET('foo', mymap)";
+ assertThat(run(query, vars), equalTo("bar"));
+ }
+
+ @Test
+ public void testMapPutDefault() {
+ Map vars = new HashMap() {{
+ put("mymap", null);
+ }};
+ String query = "MAP_PUT('foo','bar', mymap)";
+ Map result = (Map) run(query, vars);
+ assertThat(result, instanceOf(Map.class));
+ assertThat(result.size(), equalTo(1));
+ assertThat(result.get("foo"), equalTo("bar"));
+ }
+
+ @Test(expected=ParseException.class)
+ public void mapPutTest_wrongType() throws Exception {
+ Map s = (Map) run("MAP_PUT( 'foo', 'bar', [ 'baz' ] )", new HashMap<>());
+ }
+
+ @Test
+ public void testMapMerge() {
+ {
+ Map m = (Map) StellarProcessorUtils.run("MAP_MERGE([{}, null])", new
HashMap<>());
+ Assert.assertEquals(0, m.size());
+ }
+ {
+ Map vars = new HashMap() {{
+ put("map1", ImmutableMap.of("a", 1, "b", 2));
+ put("map2", ImmutableMap.of("c", 3, "d", 4));
+ put("map3", ImmutableMap.of("e", 5, "f", 6));
+ }};
+ String query = "MAP_MERGE([map1, map2, map3])";
+ Map result = (Map) run(query, vars);
+ assertThat(result, instanceOf(Map.class));
+ assertThat(result.size(), equalTo(6));
+ assertThat(result.get("a"), equalTo(1));
+ assertThat(result.get("b"), equalTo(2));
+ assertThat(result.get("c"), equalTo(3));
+ assertThat(result.get("d"), equalTo(4));
+ assertThat(result.get("e"), equalTo(5));
+ assertThat(result.get("f"), equalTo(6));
+ }
+ {
+ String query = "MAP_MERGE( [ { 'a' : '1', 'b' : '2' }, { 'c' : '3', 'd'
: '4' }, { 'e' : '5', 'f' : '6' } ] )";
Review comment:
Done
----------------------------------------------------------------
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