Hi Dash,
Thanks for clearing that up; I can confirm that the example works now as expected. My main reason for coming back to it is the fact that I’m really stuck and not able to go any further with some pretty basic code. I was wondering if you might take a look and let me know what your thoughts are.
I’ve written, what I think, is a fairly simple Lua script:
local function aggregate_stats(map,rec)
map[‘Last’] = rec.Last
map[‘TimeStamp’] = rec.TimeStamp
map[‘TotalVolume’] = rec.TotalVolume
map[‘Bid’] = rec.Bid
map[‘Ask’] = rec.Ask
map[‘TickId’] = rec.TickId
map[‘LastSize’] = rec.LastSize
map[‘BasisForLast’] = rec.BasisForLast
map[‘TradeMarketCtr’] = rec.TradeMarketCtr
map[‘TradeCondition’] = rec.TradeCondition
map[‘i’] = map[‘i’] + 1
return map
end
function stream_bin(stream)
return stream : aggregate(map{i = 0, TimeStamp=0, Last=0, TotalVolume=0, Bid=0, Ask=0, TickId=0, LastSize=0, BasisForLast=0, TradeMarketCtr=0, TradeCondition=0},aggregate_stats) --: reduce(reduce_stats)
end
I’ve included all the fields that I may eventually want to return but for now I’m only using i, for the count, and last. Here’s the C# script.
#r “E:\Master\aerospike-client-csharp-master\aerospike-client-csharp-master\AerospikeClient\bin\Debug\AerospikeClient.dll”
using System;
using System.IO;
using Aerospike.Client;
AerospikeClient client = new AerospikeClient(“192.168.2.68”, 3000);
string luaDirectory = @“E:\”;
LuaConfig.PackagePath = luaDirectory + @“?.lua”;
string filename = “stream_example.lua”;
string path = Path.Combine(luaDirectory, filename);
RegisterTask rt = client.Register(null, path, filename, Language.LUA);
rt.Wait();
string ns = “test”;
string setName = “CL_TickSmall”;
string indexName = “TradeMarketSmall”;
string indexOnName = “TickId”;
string computeOnName = “Last”;
IndexTask it = client.CreateIndex(null, ns, setName, indexName, indexOnName, IndexType.NUMERIC);
it.Wait();
Statement stmt = new Statement();
stmt.SetNamespace(ns);
stmt.SetSetName(setName);
stmt.SetBinNames(computeOnName);
stmt.SetFilters(Filter.Range(“TradeMarketCtr”,0, 36));
ResultSet rs = null;
rs = client.QueryAggregate(null, stmt, “stream_example”, “stream_bin”, Value.Get(computeOnName));
if (rs.Next())
{
Dictionary<object, object> result = (Dictionary<object, object>)rs.Object;
Console.WriteLine("Last: " + BitConverter.Int64BitsToDouble((long)(result[“Last”])));
Console.WriteLine("i " + result[“i”]);
}
And of course the database looks like this:
aql> select * from test.CL_TickTxt
±--------------------------±--------±---------±------------±--------±--------±----------±-------------±---------------±---------------+
| TimeStamp | Last | LastSize | TotalVolume | Bid | Ask | TickId | BasisForLast | TradeMarketCtr | TradeCondition |
±--------------------------±--------±---------±------------±--------±--------±----------±-------------±---------------±---------------+
| “2015-01-13 00:02:35.232” | “45.31” | “1” | “15880” | “45.30” | “45.31” | “3413790” | “C” | 36 | “01” |
| “2015-01-13 00:04:11.504” | “45.30” | “1” | “15896” | “45.30” | “45.31” | “3414570” | “C” | 36 | “01” |
| “2015-01-13 00:01:40.250” | “45.30” | “1” | “15876” | “45.29” | “45.30” | “3413650” | “C” | 36 | “01” |
| “2015-01-13 00:03:35.559” | “45.30” | “1” | “15887” | “45.30” | “45.31” | “3414393” | “C” | 36 | “01” |
| “2015-01-13 00:01:11.093” | “45.30” | “1” | “15868” | “45.29” | “45.30” | “3413611” | “O” | 36 | “4D” |
There are 58 records in the real table (I just copy pasted a few here for example). I realize that I have to do a filter as Aerospike needs to run a query before the aggregation but I’m attempting to filter on “TradeMarketCtr” which is always = 36 so that I get all the records. My assumption is that the aggregate function iterates all the records. It’s not clear from documentation if this is the case but if I use a condition to filter one specific record then the count is one. However with the above the count is always 10, not 58, which is what I would expect it to be. I’ve tried using filter.equal and filter.range, I’ve changed the value type for the TraderMarketCtr from Text to Int to long and nothing improves the situation. I’m I doing something really stupid here or is there something really broken?
Thanks… any advice you can give me will be major help. Clearing this issue will mean the different between continuing to attempt to use Aerospike or moving on to evaluate something else. This is potentially a very large project and I’ve spent a considerable amount of time writing an objective C to .Net integration piece. I would hate for that to have been for nothing.
Thanks