How to insert floating point numbers in Aerospike KV store?

I am using Aerospike 3.40. The floating point bin is not displayed. I am using python client. Please, help.

+5
source share
3 answers

The server does not support float support. It supports integers, strings, bytes, lists, and maps. Different clients handle unsupported types differently. For example, a PHP client will serialize other types, such as boolean and float, and store them in a byte field, and then deserialize them when reading. The Python client will do this starting with the next version (> = 1.0.38).

However, this approach has a limitation that makes it difficult for different clients (such as PHP and Python) to read such serialized data, since it is not serialized using a common format.

One common way to get around this with float is to turn them into integers. For example, if you have a bit called "currency", you can multiply the float by 100, chop off the mantissa and save it as a whole. Along the way, you simply divide by 100. A similar method is to save significant numbers in one bin and mantissa in another, both of which are integer types and recombine them when reading. So 123.456789 is stored as v_sig and v_mantissa.

(v_sig, v_mantissa) = str(123.456789).split('.') 

when reading you combine the two

 v = float(v_sig)+float("0."+str(v_mantissa)) 

FYI floating are now supported in place as double versions of aerospace server versions>> 3.6.0 . Most clients, such as Python and PHP, support as_double floating-point casting.

+4
source

Now it is supported in version Aerospike 3.6

+5
source

A floating point number can be divided into two parts, before and after the decimal point, and save them in two cells and use them in the application code.

However, when creating more bins, Aerospike's performance overhead will be used as the new malloc for each container.

If switching from Python to any other language is not used, it is better to use the best serialization mechanism and save it in one box. This means that only one bit per floating point will be used, and will also reduce the size of the data in Aerospike. The small amount of data in Aerospike always helps in speed in terms of network I / O, which is the main purpose of caching.

+1
source

Source: https://habr.com/ru/post/1213754/


All Articles