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.
Asked
Active
Viewed 414 times
1

Carbonrock
- 457
- 2
- 15
-
Looks a very genuine problem to me. – sunil Jun 27 '15 at 10:05
2 Answers
2
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);

Helipilot50
- 227
- 1
- 1
-
@ Helipilot50, I have mentioned about using getFloat() in my question. My problem is, I do not want to use getFloat explicitly on retrieval. Python client does this for me. – Carbonrock Jul 08 '15 at 13:20
1
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.
double value = 22.7;
Bin bin = new Bin("mybin", (Object) value);

sunil
- 3,507
- 18
- 25