I am Using Aerospike 3.40. Bin with floating point value doesn't appear. I am using python client. Please help.
-
could you please explain more. its not clear. – Milad Faridnia Feb 19 '15 at 19:56
-
1Milad, Looks like Aerospike KV store does not support floating point numbers. Can any one explain how to achieve this? – Carbonrock Feb 19 '15 at 20:12
-
Dear Dhanasekaran S Thanks for your explanation. If you want answers you need to add more data about your problem. ;) – Milad Faridnia Feb 19 '15 at 20:18
-
I think this link will help you asking good questions. http://stackoverflow.com/help/how-to-ask – Milad Faridnia Feb 19 '15 at 20:19
3 Answers
The server does not natively support floats. It supports integers, strings, bytes, lists, and maps. Different clients handle the unsupported types in different ways. The PHP client, for example, will serialize the other types such as boolean and float and store them in a bytes field, then deserialize them on reads. The Python client will be doing that starting with the next release (>= 1.0.38).
However, this approach has the limitation of making it difficult for different clients (PHP and Python, for example) to read such serialized data, as it's not serialized using a common format.
One common way to get around this with floats is to turn them into integers. For example, If you have a bin called 'currency' you can multiply the float by 100, chop off the mantissa, and store it as an integer. On the way out you simply divide by 100. A similar method is to store the significant digits in one bin and the mantissa in another, both of them integer types, and recombine them on the read. So 123.456789 gets stored as v_sig and v_mantissa.
(v_sig, v_mantissa) = str(123.456789).split('.')
on read you would combine the two
v = float(v_sig)+float("0."+str(v_mantissa))
FYI, floats are now supported natively as doubles on the aerospike server versions >= 3.6.0. Most clients, such as the Python and PHP one supports casting floats to as_double.

- 6,951
- 22
- 41
-
Ronen, Thanks for your reply. I have tried using struct.pack to convert float to byte array then insert into aerospike bin. But I am unable to retrieve back from aerospike using python client. Core Dump error thrown. Also how do I find on which column I need to deserialize to convert back to float. Can you please explain in detail? Thanks in advance. – Carbonrock Mar 05 '15 at 07:31
-
1Hey Dhanasekaran, if you run into a bug you can (and should) open a GitHub issue at the repo https://github.com/aerospike/aerospike-client-python/issues/. A 1.0.38 release is pending soon. If the problem persists please do that. – Ronen Botzer Mar 06 '15 at 00:58
-
Ronen, Thanks for your valuable reply. 1.0.38 is out and I have tested which floating point bins are not getting appeared. Can you please help me out? Update: – Carbonrock Mar 14 '15 at 08:04
-
Update: Getting huge list of warnings as given blow while upgrading to 1.0.38 using pip. will this be a reason? Was floating point issue handled in this release? ./aerospike-client-c/include/aerospike/as_udf.h:255:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes] – Carbonrock Mar 14 '15 at 08:11
-
Hey, you can actually open a new issue on the GitHub repo, if you're running into a problem, though warnings aren't a bug per-se. No, floating point is not handled in the release, because it would first change on the server before the clients. That's not planned soon. – Ronen Botzer Mar 15 '15 at 03:05
-
Ronen, Thanks for your reply. As per your Answer you mentioned in the beginning of this post, "The PHP client, for example, will serialize the other types such as boolean and float and store them in a bytes field, then deserialize them on reads. The Python client will be doing that starting with the next release (>= 1.0.38)" I expected the python client 1.0.38 may do this. May I now when this fix will be out? What will be my temporary fix till then? Also can you explain in brief for what is the difficulty in supporting Floats in Aerospike? – Carbonrock Mar 16 '15 at 07:38
-
-
3Okay, I pushed out a new Python aerospike 1.0.40 release, and unsupported types such as floats will now be handled automatically for you. See the release notes (https://github.com/aerospike/aerospike-client-python/releases/tag/1.0.40) and try it for yourself. – Ronen Botzer Mar 19 '15 at 00:42
-
1Ronen, thanks and this is a timely release from you. Thanks to you and aerospike team. – Carbonrock Mar 19 '15 at 07:23
-
@RonenBotzer Let me know if we have similar thing for Java client as well. – Ankur Choudhary Jun 02 '15 at 17:27
Floating point number can be divided into two parts, before decimal point and after it and storing them in two bins and leveraging them in the application code.
However, creating more number of bins have performance overheads in Aerospike as a new malloc will be used per bin.
If switching from Python to any other language is not the use case, it is better to use a better serialization mechanism and save it in single bin. That would mean only one bin per floating number is used and also will reduce the data size in Aerospike. Lesser amount of data in Aerospike always helps in speed in terms of Network I/O which is the main aim of Caching.

- 485
- 1
- 9
- 18
-
Ankur, thanks for ur reply. this effort is currently taken care by the recent release of Python client by Ronen botzer. – Carbonrock May 08 '15 at 08:37
-
Sure. Don't think if same thing is planned for Java client as well. – Ankur Choudhary Jun 02 '15 at 06:54
-
@ Ankur, Yes. Currently I am looking for the same feature in Java Client. Which is not supported at present. Any thoughts how to handle this? – Carbonrock Jun 18 '15 at 13:09
-
Either store them in two bins and merge them in your application or use them as is and Aerospike will store them as Blob. My answer above should help your use case. – Ankur Choudhary Jun 18 '15 at 16:11