Atomic increment for nested map

Hey, currently on Aerospike Java client we support increment for maps using MapOperation.increment(mapPolicy, bin, mapKey, value) → Map<Long, Long>

is there someway we can increment a nested map Map<Long, Map<Long, Long>> MapOperation.increment(mapPolicy, bin, mapKey, mapSecondKey, value)

If something like this doesn’t exist yet, would udf be another way of handling these?

I tried the following command and that didn’t work either MapOperation.put(mapPolicy, “map”, Value.get(“count”), Value.get(10), CTX.mapKey(Value.get(“123”))))

and I get the following error : com.aerospike.client.AerospikeException: Error 26,1,30000,5000,1,BB9979897BC230A 172.17.35.56 3000: Operation not applicable

Yes, but it will depend on the version of the Java client and Aerospike server that you are running.

The MapOperation.increment in the current Java version (5.0.2) supports passing a context to find the element to apply the operation to.

Aerospike 4.6.0.2 introduced support for nested List/Map update operations via context parameter.

Aerospike 4.9.0.3 introduced support for nested List/Map operations via context parameter that can create the elements in the context path (similar to mkdir -p).

I updated to 5.0.2 when I got the error that operation is not supported

Is there a top level map key of “123”? Since you mention they are Long keys, did you mean Value.get(123), without the quotes?

You are correct. I double checked the method expected structure : {321={123=100}}

MapOperation.put(
    MapPolicy.Default,
    "bin",
    Value.get(123),
    Value.get(100),
    CTX.mapKey(Value.get(321))));

following the example from here : https://www.aerospike.com/apidocs/java/com/aerospike/client/cdt/MapOperation.html#increment-com.aerospike.client.cdt.MapPolicy-java.lang.String-com.aerospike.client.Value-com.aerospike.client.Value-com.aerospike.client.cdt.CTX…-

The aerospike server version is 4.9.0.11 and client version is 5.0.2.

@kporter are there are examples to compare what might be wrong here?

That should work if the top level key 321 already exist.

If I use increment instead of put, do both keys still need to exist? For regular maps if key doesn’t exist MapOperation.increment creates the key. Should it work the same way for nested maps?

You have to specify a context flag for that to happen. That has been implemented since 4.9.0.3. I’m not sure how to do that in Java but the context flag to create context (if it didn’t exist) should be there.

The Java APIs for context can be found here: https://www.aerospike.com/apidocs/java/com/aerospike/client/cdt/CTX.html

You would be interested in the APIs suffixed “create”.

Thank for all the help, it works now.