I came to know that Java Client 3.0.33 supports Float/Double datatype at client side.
The release notes says: Support double/float on client-side. Server will store these values as longs.
This is fine. When I insert a float value to aerospike bin, It is stored as a long integer in aerospike server. Whereas while retreiving the value back using Java Client, it is getting as Long integer as saved in the server.
I expect Java Client should have converted Long to float automatically on retrieval. This is perfectly done in python client (serialize/deserialize).
I have to explicitly use getFloat() to convert back to float while using Java Client.
My Question is how do I know for which bin I need to apply getFloat() and for which bin I should not. Because I never know the datatype I am reading was inserted as float.
Thanks in Advance.
Handling Float/Double datatypes using Aerospike Java Client
441 views Asked by Carbonrock At
2
There are 2 answers
1
On
Use the Aerospike Java client 3.1.2 with the following code. The double/float is stored as a serialized Java type, but so long as you write and read with Jave you will be fine.
Key key = new Key("test", "some-floats", "float-001");
Bin bin = new Bin("a-float", 3.14159f);
this.client.put(null, key, bin);
Record record = this.client.get(null, key, "a-float");
double pi = record.getFloat("a-float");
System.out.println("Float:"+pi);
A workaround is given in latest Aerospike java client (3.1.4 which is about to be released) to force the client to always go via the java object serialization/deserialization. It avoids the conversion to long by the client. A sample code is as below.