Aerospike - Check/Increment for NIL value in a list?

Dante Adams :

If I run this code, it increments whatever the value is present at Index 7, if any of the index before 7 are not present, it simply puts NIL as its value

Code

Operation operation = ListOperation.increment( "incre", 7 );
client.operate( policy, key, operation );

AQL

aql> select * from test.users
+----+----------------------------------------+
| PK | incre                                  |
+----+----------------------------------------+
| 2  | LIST('[1, 1, 1, 2, 1, 1, NIL, 1]') |
+----+----------------------------------------+
1 row in set (0.095 secs)

As you can see, index 6 didn't exist, so aerospike automatically put NIL in its place. If I try to increment index 6, I get this error.

Exception in thread "main" com.aerospike.client.AerospikeException: Error 4,1,30000,0,0,BB955892AFD8CA0 127.0.0.1 3000: Parameter error

My questions :-

1) Is it possible to put any sort of default value instead of NIL for indexes which dont exist? If there is no way to check for NIL, is it possible to increment NIL?

2) Is there a way to check for NIL value before incrementing it?

sunil :

Increment operation assumes that the data type is integer. So, when you try to increment at position 7, and there is no element there yet, it starts with integer 0 and increments to 1. However, as you noticed, 6th position is filled with NIL as the list needs to be continuous. Now the problem is that NIL is not an integer. So, you cannot increment it.

To answer your specific questions:

  1. No, it is not possible to fill with a specific default value.
  2. You can read the element at a position you can use the getType() of the Value class to know if the element is null type.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=415782&siteId=1