I wrote a complete program on Windows from your code and it returns the same info as AQL. I suspect there is a problem opening “audit_filters.lua” on clients running in mono on Linux (I don’t have a test environment for this configuration).
The lua functions are run on both server and client (final reduce) for aggregation queries. “audit_filters.lua” must be readable from the client machine. “audit_filters.lua” does not need to be shared with the server. I recommend keeping “audit_filters.lua” in a separate client directory from the server, so there is no contention when reading the file.
I still would like to know if AerospikeDemo QuerySum works for you?
Set HOST and LUA_DIR variables and place “audit_filters.lua” in your LUA_DIR directory.
using System;
using System.IO;
using System.Collections;
using System.Text;
using Aerospike.Client;
namespace AggregationTest
{
class AggregationTest
{
private const string HOST = "bn66";
private const string LUA_DIR = "C:/Users/bnichols/udf/";
static void Main(string[] args)
{
try
{
Log.SetCallback(Logger);
LuaConfig.PackagePath = LUA_DIR + "?.lua";
AerospikeClient client = new AerospikeClient(null, HOST, 3000);
try
{
RunTest(client);
}
finally
{
client.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
}
private static void RunTest(AerospikeClient client)
{
string packageName = "audit_filters.lua";
RegisterTask rt = client.Register(null, LUA_DIR + packageName, packageName, Language.LUA);
rt.Wait();
IndexTask it = client.CreateIndex(null, "audit", "year2016", "appindex", "application", IndexType.STRING);
it.Wait();
client.Put(null, new Key("audit", "year2016", 1), new Bin("application", "aaaaaaaaaaaa"), new Bin("subject", "111"));
client.Put(null, new Key("audit", "year2016", 2), new Bin("application", "availability"), new Bin("subject", "222"));
client.Put(null, new Key("audit", "year2016", 3), new Bin("application", "availability"), new Bin("subject", "321"));
client.Put(null, new Key("audit", "year2016", 4), new Bin("application", "availability"), new Bin("subject", "321"));
client.Put(null, new Key("audit", "year2016", 5), new Bin("application", "bbbbbbbbbbbb"), new Bin("subject", "321"));
var statement = new Statement();
statement.SetNamespace("audit");
statement.SetSetName("year2016");
statement.SetFilters(new Filter[] { Filter.Equal("application", "availability") });
var resultSet = client.QueryAggregate(null, statement, "audit_filters", "filterBySubject", Value.Get("321"));
try
{
while (resultSet.Next())
{
object obj = resultSet.Object;
if (obj is IDictionary)
{
Console.WriteLine(MapToString((IDictionary)obj));
}
else
{
Console.WriteLine(obj.ToString());
}
}
}
finally
{
resultSet.Close();
}
client.DropIndex(null, "audit", "year2016", "appindex");
}
private static string MapToString(IDictionary map)
{
StringBuilder sb = new StringBuilder(200);
MapToString(sb, map);
return sb.ToString();
}
private static void MapToString(StringBuilder sb, IDictionary map)
{
sb.Append('[');
int i = 0;
foreach (DictionaryEntry entry in map)
{
if (i > 0)
{
sb.Append(", ");
}
sb.Append('{');
sb.Append(entry.Key);
sb.Append(",");
sb.Append(entry.Value);
sb.Append('}');
i++;
}
sb.Append(']');
}
private static void Logger(Log.Level level, string message)
{
Console.WriteLine(level.ToString() + ':' + message);
}
}
}