Operate fails when WritePolicy has a Condition

I am working on an enterprise project for a large organization that is onboarding onto Aerospike. I am building a piece of functionality that essentially requires the following workflow: for a given record, (1) check if a condition about the record’s current state is true and (2) if it is, perform a set of update actions on the record’s bins.

To accomplish this, I am using Aerospike’s client.operate method in the Java client. However, when I set the filterExp field of the policy, it causes the operation to fail with a Parameter error. As far as I was able to tell, this behavior was not documented - if anything, it seems it should succeed in the same way a put request would. Therefore, I believe it’s a bug (and if it’s not, would it be possible to update the documentation to show that this is not supported)?

Here’s some more information: Java library version: 5.0.4 Server Version: 5.5.0.2 , latest (running inside a container)

Here is a minimum working example:

IAerospikeClient client = new AerospikeClient(HOST_NAME, PORT);
WritePolicy wp = new WritePolicy(client.getWritePolicyDefault());
wp.filterExp = Exp.build(Exp.val(true));

Operation op = Operation.put(new Bin("bin", "val"));
Key key = new Key(NAMESPACE, null, "key");

client.put(null, key, new Bin("bin", "val2"));

client.operate(wp, key, op);

And the corresponding error:

com.aerospike.client.AerospikeException: Error 4,1,0,30000,0,0,BB9030011AC4202 127.0.0.1 55727: Parameter error
	at com.aerospike.client.command.ReadCommand.parseResult(ReadCommand.java:179)
	at com.aerospike.client.command.SyncCommand.executeCommand(SyncCommand.java:104)
	at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:64)
	at com.aerospike.client.AerospikeClient.operate(AerospikeClient.java:1457)

Apologies if this is tagged incorrectly, or in the wrong place.

I am not an expert when it comes to building expression filters, but per the doc, it seems the expression you built is not complete. You would need to specify the bin you are comparing against and the operator to be used.

This doc has some example: Documentation | Aerospike

wp.filterExp = Exp.build(Exp.ne(Exp.stringBin("bin"), Exp.val("val")));

So I think this would select the record if the bin with name “bin” does not have a value equal to “val”.

Let me know if this is not correct.

Expressions cannot be a single value like true, false, numbers, etc. You can easily bypass this limitation if you really need it:

Exp.or(Exp.val(true), Exp.val(true));

Thank you, that solved the issue!

We plan to remove this restriction for 5.6.

So for 5.6+, the following would be a legal expression:

Exp.val(true)
1 Like

Thank you both, this was the issue.

© 2021 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.