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: https://www.aerospike.com/docs/guide/expressions/comparison/

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.

Hi Kporter,

We are facing similar exception for below Expression. aerospike-client-5.0.1 is the version is used in our application.

Expression lExpSinceLUT = Exp.build(
                Exp.le(Exp.sinceUpdate(),
                        Exp.val((EndTime - StartTime))));

Where StartTime and EndTime are long datatype

Below is the exception Caused by: com.aerospike.client.AerospikeException: Error 4,1,10000,10000,3,BB937F1A3270008 127.0.0.1 3000: Parameter error at com.aerospike.client.command.MultiCommand.parseGroup(MultiCommand.java:242) at com.aerospike.client.command.MultiCommand.parseResult(MultiCommand.java:219) at com.aerospike.client.command.SyncCommand.executeCommand(SyncCommand.java:103) at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:64) at com.aerospike.client.command.MultiCommand.executeAndValidate(MultiCommand.java:98) at com.aerospike.client.query.QueryExecutor$QueryThread.run(QueryExecutor.java:134)

Which version of the server is this running against? I just tried it against version 5.7 with some random EndTime / StartTime and it didn’t seem to complain…