Maps { @UserFunction @Description("apoc.map.submap(map,keys,[defaults],[fail=true]) - returns submap for keys or throws exception if one of the key doesn't exist and no default value given at that position") public Map<String, Object> submap(@Name("map") Map<String,Object> map, @Name("keys") List<String> keys, @Name(value = "values", defaultValue = "[]") List<Object> values, @Name(value = "fail",defaultValue = "true") boolean fail) { if (keys==null || map==null) return null; int keySize = keys.size(); Map<String,Object> result = new LinkedHashMap<>(keySize); int valuesSize = values == null ? -1 : values.size(); for (int i = 0; i < keySize; i++) { String key = keys.get(i); result.put(key, get(map, key, i < valuesSize ? values.get(i) : null,fail)); } return result; }  @UserFunction @Description("apoc.map.groupBy([maps/nodes/relationships],'key') yield value - creates a map of the list keyed by the given property, with single values") Map<String,Object> groupBy(@Name("values") List<Object> values, @Name("key") String key); @UserFunction @Description("apoc.map.groupByMulti([maps/nodes/relationships],'key') yield value - creates a map of the list keyed by the given property, with list values") Map<String,List<Object>> groupByMulti(@Name("values") List<Object> values, @Name("key") String key); Object getKey(@Name("key") String key, Object value); @UserFunction @Description("apoc.map.fromNodes(label, property)") Map<String, Node> fromNodes(@Name("label") String label, @Name("property") String property); @UserFunction @Description("apoc.map.fromPairs([[key,value],[key2,value2],...])") Map<String,Object> fromPairs(@Name("pairs") List<List<Object>> pairs); @UserFunction @Description("apoc.map.fromLists([keys],[values])") Map<String,Object> fromLists(@Name("keys") List<String> keys, @Name("values") List<Object> values); @UserFunction @Description("apoc.map.values(map, [key1,key2,key3,...],[addNullsForMissing]) returns list of values indicated by the keys") List<Object> values(@Name("map") Map<String,Object> map, @Name(value = "keys",defaultValue = "[]") List<String> keys, @Name(value = "addNullsForMissing",defaultValue = "false") boolean addNullsForMissing); @UserFunction @Description("apoc.map.fromValues([key1,value1,key2,value2,...])") Map<String,Object> fromValues(@Name("values") List<Object> values); @UserFunction @Description("apoc.map.merge(first,second) - merges two maps") Map<String,Object> merge(@Name("first") Map<String,Object> first, @Name("second") Map<String,Object> second); @UserFunction @Description("apoc.map.mergeList([{maps}]) yield value - merges all maps in the list into one") Map<String,Object> mergeList(@Name("maps") List<Map<String,Object>> maps); @UserFunction @Description("apoc.map.get(map,key,[default],[fail=true]) - returns value for key or throws exception if key doesn't exist and no default given") Object get(@Name("map") Map<String,Object> map, @Name("key") String key, @Name(value = "value", defaultValue = "null") Object value, @Name(value = "fail",defaultValue = "true") boolean fail); @UserFunction @Description("apoc.map.mget(map,key,[defaults],[fail=true]) - returns list of values for keys or throws exception if one of the key doesn't exist and no default value given at that position") List<Object> mget(@Name("map") Map<String,Object> map, @Name("keys") List<String> keys, @Name(value = "values", defaultValue = "[]") List<Object> values, @Name(value = "fail",defaultValue = "true") boolean fail); @UserFunction @Description("apoc.map.submap(map,keys,[defaults],[fail=true]) - returns submap for keys or throws exception if one of the key doesn't exist and no default value given at that position") Map<String, Object> submap(@Name("map") Map<String,Object> map, @Name("keys") List<String> keys, @Name(value = "values", defaultValue = "[]") List<Object> values, @Name(value = "fail",defaultValue = "true") boolean fail); @UserFunction @Description("apoc.map.setKey(map,key,value)") Map<String,Object> setKey(@Name("map") Map<String,Object> map, @Name("key") String key, @Name("value") Object value); @UserFunction @Description("apoc.map.setEntry(map,key,value)") Map<String,Object> setEntry(@Name("map") Map<String,Object> map, @Name("key") String key, @Name("value") Object value); @UserFunction @Description("apoc.map.setPairs(map,[[key1,value1],[key2,value2])") Map<String,Object> setPairs(@Name("map") Map<String,Object> map, @Name("pairs") List<List<Object>> pairs); @UserFunction @Description("apoc.map.setLists(map,[keys],[values])") Map<String,Object> setLists(@Name("map") Map<String,Object> map, @Name("keys") List<String> keys, @Name("values") List<Object> values); @UserFunction @Description("apoc.map.setValues(map,[key1,value1,key2,value2])") Map<String,Object> setValues(@Name("map") Map<String,Object> map, @Name("pairs") List<Object> pairs); @UserFunction @Description("apoc.map.removeKey(map,key,{recursive:true/false}) - remove the key from the map (recursively if recursive is true)") Map<String,Object> removeKey(@Name("map") Map<String,Object> map, @Name("key") String key,  @Name(value="config", defaultValue = "{}") Map<String, Object> config); @UserFunction @Description("apoc.map.removeKeys(map,[keys],{recursive:true/false}) - remove the keys from the map (recursively if recursive is true)") Map<String, Object> removeKeys(@Name("map") Map<String, Object> map, @Name("keys") List<String> keys, @Name(value = "config", defaultValue = "{}") Map<String, Object> config); @UserFunction @Description("apoc.map.clean(map,[skip,keys],[skip,values]) yield map filters the keys and values contained in those lists, good for data cleaning from CSV/JSON") Map<String,Object> clean(@Name("map") Map<String,Object> map, @Name("keys") List<String> keys, @Name("values") List<Object> values); @UserFunction @Description("apoc.map.updateTree(tree,key,[[value,{data}]]) returns map - adds the {data} map on each level of the nested tree, where the key-value pairs match") Map<String,Object> updateTree(@Name("tree") Map<String, Object> tree, @Name("key") String key, @Name("data") List<List<Object>> data); @UserFunction @Description("apoc.map.flatten(map, delimiter:'.') yield map - flattens nested items in map using dot notation") Map<String,Object> flatten(@Name("map") Map<String, Object> map, @Name(value="delimiter", defaultValue = ".") String delimiter); @UserFunction @Description("apoc.map.sortedProperties(map, ignoreCase:true) - returns a list of key/value list pairs, with pairs sorted by keys alphabetically, with optional case sensitivity") List<List<Object>> sortedProperties(@Name("map") Map<String, Object> map, @Name(value="ignoreCase", defaultValue = "true") boolean ignoreCase); @Context
    public Transaction tx; }
@Test public void testSubMap() throws Exception { TestUtil.testCall(db, "RETURN apoc.map.submap({a:1,b:1},['a']) AS value", (r) -> { assertEquals(map("a",1L),r.get("value")); }); TestUtil.testCall(db, "RETURN apoc.map.submap({a:1,b:2},['a','b']) AS value", (r) -> { assertEquals(map("a",1L,"b",2L),r.get("value")); }); TestUtil.testCall(db, "RETURN apoc.map.submap({a:1,b:1},['c'],[42]) AS value", (r) -> { assertEquals(map("c",42L),r.get("value")); }); TestUtil.testCall(db, "RETURN apoc.map.submap({a:1,b:1},['c'],null,false) AS value", (r) -> { assertEquals(map("c",null),r.get("value")); }); TestUtil.testFail(db, "RETURN apoc.map.submap({a:1,b:1},['c']) AS value", IllegalArgumentException.class); TestUtil.testFail(db, "RETURN apoc.map.submap({a:1,b:1},['a','c']) AS value", IllegalArgumentException.class); }