Int values from C# Client


First I would like to congratulate Aerospike for their outstanding work. I’ve only started evaluating but so far I am very impressed. Despite that, and the excellent documentation, I am having a strange issue that I was hoping someone could help me with. I’m using the Vagrant VM for OSX and connecting to it from a VMWare Fusion VM on the same Mac; I had to play with the Vagrant default networking (disable port forwarding and enable bridging) but communication is working fine. I can write and read from the DB.

I’m uploading price data from a CSV to Aerospike as follows:

var ns = “test”; var set = “CL_Tick4”; var csvResource = “Z:\SSD\IQFeed\CL.txt”;

// Initialize policy. WritePolicy policy = new WritePolicy(); policy.timeout = 500; // 50 millisecond timeout.

// Establish connection the server AerospikeClient client = new AerospikeClient(“”, 3000);

var streamReader = new StreamReader(csvResource); using (var streadmReader = new StreamReader(csvResource)) { string line = streamReader.ReadLine(); while (line != null) { var tokens = line.Split(’,’); if (tokens.Count() == 10) { int objectID = int.Parse(tokens[6], NumberFormatInfo.InvariantInfo); Key key = new Key(ns, set, objectID); Bin TimeStamp = new Bin(“TimeStamp”, DateTime.Parse(tokens[0])); Bin Last = new Bin(“Last”, double.Parse(tokens[1])); Bin LastSize = new Bin(“LastSize”, int.Parse(tokens[2])); Bin TotalVolume = new Bin(“TotalVolume”, int.Parse(tokens[3])); Bin Bid = new Bin(“Bid”, double.Parse(tokens[4])); Bin Ask = new Bin(“Ask”, double.Parse(tokens[5])); Bin TickId = new Bin(“TickId”, int.Parse(tokens[6])); Bin BasisForLast = new Bin(“BasisForLast”, tokens[7]); Bin TradeMarketCenter = new Bin(“TradeMarketCtr”, int.Parse(tokens[8])); Bin TradeConditions = new Bin(“TradeCondition”, tokens[9]); client.Put(policy, key, TimeStamp, Last, LastSize, TotalVolume, Bid, Ask, TickId, BasisForLast, TradeMarketCenter, TradeConditions); } line = streamReader.ReadLine(); } }

This operating completes and the set appears to contain all the records… here’s what the output from AQL looks like for one row:

| 00 01 00 00 00 FF FF FF FF 01 00 00 00 00 00 00 00 04 01 00 00 00 0F 53 79 73 74 65 6D 2E 44 61 74 65 54 69 6D 65 02 00 00 00 05 74 69 63 6B 73 08 64 61 74 65 44 61 74 61 00 00 09 10 40 A9 B4 1F A9 FF D1 08 40 A9 B4 1F A9 FF D1 08 0B | 4632016955995198587 | 1 | 287595 | 4632012733870547927 | 4632014141245431480 | 14767640 | “C” | 36 | “01” |

This has me a little confused, as the output doesn’t resemble the input, however I’m assuming that Aerospike’s internal datatypes are going to be different from what I passed in. I’m using two examples to learn how to query the db from C#. The first is the Twitter sample application and the second is the Query example in the C# Client documentation. First, let me say, that if I upload the same data to Aerospike as text, without parsing to c# value types first, and run the twitter example, it works; I can return a price using the TickId as a secondary index.

If, however, I kill that index and create a new numeric one, and use the datatype parsed file and attempt to return an integer like this:

rs = client.Query(null, stmt); while (rs.Next()) { Record r = rs.Record; var result = Convert.ToDouble(r.GetValue(“last”)); Console.WriteLine(result); }

I get this:

Here’s 5634976’s Last:


If I modify that and don’t convert the value like this: rs = client.Query(null, stmt); while (rs.Next()) { Record r = rs.Record; Console.WriteLine(r.GetValue(“Last”)); }

I get 4631596150905016156

If, however, I use the examples to do a simple write of one record, using the name / age example, I get the age=25 with no issue. So I’m assuming that there is some issue with the way I am parsing the CSV and sending it up to Aerospike…

I hope that was enough information, if you require more clarification please let me know. Any assistance you can offer would be greatly appreciated.

Kind Regards



Just as an update, I incorrectly stated that it was “int” values… that’s not the problem. The problem is with doubles…



Ok, so I just figured this out, and I have to say that this really should be better documented. I found this in the sample code… It’s not obvious that GetValue is not a generic method for returning all value types. The examples using int and string which work fine for GetValue, GetDouble, however, is a different scenario…


/// Get bin value as double. /// public double GetDouble(string name) { return BitConverter.Int64BitsToDouble((long)GetValue(name)); }


The server does not yet officially support doubles, so the client uses a work-around by storing double bits in a long. This is why using GetValue() directly does not work. When the server starts supporting double field types, then GetValue() would return a double. In any event, using GetDouble() is the preferred method going forward.


Thanks Brian… I don’t have an issue with any of that… it’s the inconsistency and lack of supporting documentation that makes it difficult. If you had provided an example of how to use “unsupported” value types it would have saved me a half a day. Both examples use supported value types and there is no indication whatsoever that an alternate approach may be required for something different. You do mention that various types need to be serialized / deserialized by the calling language but there’s nothing concrete to demonstrate how to use it. That’s all…

Otherwise I think your product is fantastic…



Actually this takes me to the next thing I need to evaluate… I want to write a UDF that uses the doubles to perform a reduce. According to this: doubles aren’t supported but byte arrays are… my apologies, I have zero Lua experience, are you able to direct me to some information about how I could use the byte array functionality to make use of my stored doubles?




Never mind I see… you’re using a 64bit int to store the double… I can work with that.

closed #9

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.