Upsert error

Hello,

I am trying to update a bin inserting other bin with the same PK.

I am using java client version 3.0.31 and aerospike community server version 3.3.22.

If the bin to update is an Integer the update operation add the column value to the previous column value. For example

in aql:

aql> select * from catalog_functional_test.assimpleinserttest ±---------+ | column_2 | ±---------+ | 6 | ±---------+

With java code I insert a bin with the same PK and column_2 value is equal to 8.

Again in aql:

aql> select * from catalog_functional_test.assimpleinserttest ±---------+ | column_2 | ±---------+ | 14 | ±---------+

If the column_2 is a String column the result is the following exception:

com.aerospike.client.AerospikeException: Error Code 12: Bin type error at com.aerospike.client.command.WriteCommand.parseResult(WriteCommand.java:59) at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:56) at com.aerospike.client.AerospikeClient.add(AerospikeClient.java:360).

Could somebody help me?

Thank you.

It looks like you are building up an Aerospike.operate() sequence on the record. Can you give the code which constructs the “operate()” call?

Hello,

I am using the add method from the java api.

The first time I invoke: aerospikeClient.add(writePolicy, key, bins);

With this parameters: writePolicy → writePolicy.recordExistsAction = RecordExistsAction.UPDATE; key → new Key(“catalog_functional_test”, assimpleinserttest, “1”) bins–> [column_2:6]

The second time I invoke the same api method with this parameters: writePolicy → writePolicy.recordExistsAction = RecordExistsAction.UPDATE; key → new Key(“catalog_functional_test”, assimpleinserttest, “1”) bins–> [column_2:8]

I don’t use the operate api method.

Thanks.

Hi,

The “add” operation increments or decrements an Integer Bin value by the amount that you pass as a parameter.

Assuming that the initial value is zero, after your firs invocation, the value of the Bin would be 6 (0 + 6 = 6). After the second invocation the value of the Bin would be 14 (6 + 8 = 14).

You cannot increment a String Bin. If you want to change the Bin type from String to Integer, you use “put” operation to over write the Bin with the new type and value.

Does this help?

1 Like