How are null bins handled?

In my database, I see a lot of empty bins of the form bin: {}. How are these bins handled by Aerospike? Would they be deleted on their own? Or do I have to write a utility that does that?

A bin set to null is automatically deleted. If you set a Bin to null (see asNull() in Bin / Java client), the bin will be deleted. If it is the last bin in the record, the record will be deleted. The deletion will be either durable or not, depending on the writepolicy in effect.

1 Like

I’m not sure which client that you are using but likely bin: {} represents a bin containing an empty map.

How are these bins handled by Aerospike?

See @pgupta response.

Would they be deleted on their own?

Empty lists or maps are considered valid values - so the server doesn’t automatically delete them.

Or do I have to write a utility that does that?

Yes, you would need to write a custom utility function to purge these values.

1 Like

Thank you. I am using java client. Due to some unknown reason, many records in my production database have ended up with lots of bins with empty maps. And I am trying to write a utility using scan callbacks which would delete those bins. However, I am finding it difficult to test it. Is there any way I can add a record in Aerospike through AQL which creates such record and helps me test my flow?

Yes, there is an example of inserting a map in the aql docs. I suspect it would be something like MAP('{}') based on the example. Correct @pgupta?

Do you know the names of the bins that you’d like to clean up or are the names somewhat random?

Try this … I have not validated. But there is the JSON qualifier that AQL supports.


INSERT INTO test.testset (PK, a) VALUES ('xyz', JSON('{}') )

bin names are random and there are a lot of them. So I need to scan the whole set itself.

Thank you, let me try these.

1 Like

see correction … in json syntax. @nbenipal keen to know if it worked. I don’t have a test setup handy.

This syntax works for me: "JSON{}"

1 Like

This is the general syntax:

1 Like

Thank you. This has been working for me now:

INSERT INTO testns.testset (PK, a) VALUES ("abc", "JSON{}");

@kporter @pgupta Thank you for your assistance. Another thing I would like to clarify is: Does aeropike distinguish whether they were inserted using MAP, LIST or GeoJSON

While trying to catch such empty bins in my utility, I am trying the below code:

Map<Object, Object> binMap;
...
for (String binName : aeRecord.bins.keySet()) {
   binMap = (Map<Object, Object>) aeRecord.getValue(binName);

   if (binMap == null) { 
   log.info("empty bin found");
   }
// other processing
}
...

However, that empty bin is ignored and no log statement pertaining to that. Hence my question that I posed above.

@kporter @pgupta Just realized that since I am able to insert bins of the bin:{} and it is considered valid by aerospike and not null. So when I am doing this binMap == null , how would that look like for aerospike? If the bin map is null, is that even a valid bin for aerospike?

I think you’d just use the map’s isEmpty() method - binMap.isEmpty().

1 Like