Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 对lua中的关联数组进行排序_Arrays_Sorting_Lua_Lua Table_Aerospike - Fatal编程技术网

Arrays 对lua中的关联数组进行排序

Arrays 对lua中的关联数组进行排序,arrays,sorting,lua,lua-table,aerospike,Arrays,Sorting,Lua,Lua Table,Aerospike,我有一个数组具有以下结构: [{"value":{"date":"2015-12-27T16:02:38.109Z", "read":"no"}, "key":"56800b9e9669ef7312d94f4c"}, {"value":{"date":"2015-12-30T13:01:30.580Z", "read":"no"}, "key":"5683d5aaec6a8c2428ca1011"},...] 我想用分页按日期降序排列这个数组 我尝试了这个例子,其中wholeList是数组的名

我有一个数组具有以下结构:

[{"value":{"date":"2015-12-27T16:02:38.109Z", "read":"no"}, "key":"56800b9e9669ef7312d94f4c"}, {"value":{"date":"2015-12-30T13:01:30.580Z", "read":"no"}, "key":"5683d5aaec6a8c2428ca1011"},...]
我想用分页按日期降序排列这个数组

我尝试了这个例子,其中wholeList是数组的名称,如果要从索引1返回到9:

 local function compare(a,b)
    return os.date(b["date"])  < os.date(a["date"])
end

function get(rec, ldtBinName, from, to)

if aerospike:exists(rec) then
  local count = llist.size(rec, ldtBinName);
    if count > 0 then
        wholeList = llist.scan(rec, ldtBinName);
        table.sort(wholeList, compare);
        return table.unpack(wholeList , from , to);

    --end if count > 0
    else
    return {};
        --rec['count'] = 0;
        --return empty array

    end
    --end else if count > 0
--end if aerospike exists
else
  return {};--end return empty array
end--end else aerospike exists
func:'as_command_parse_udf_error', 文件:“src/main/aerospeck/as_command.c”, 行:822}

注意:如果我只返回'wholeList',我得到了整个数组,那么我假设在使用table.sort时会出现错误 我错过了什么


编辑:我尝试了另一种方法:

该表不是有效的Lua代码,显示您的真实代码。错误消息告诉您,
wholeList
不是表,而是用户数据。我是Lua新手,这意味着什么?我该怎么解决呢?你需要把它做成一张桌子。你能再解释一下你想要达到的目标吗?如果您使用的是大型有序列表(LDT),它会自动按键排序。如果您的主要用例是按日期列出,为什么不使用时间戳作为毫秒精度的键(不允许重复键)?Aerospike将UDF的执行限制为1GB,因此如果LDT中的UDF超过1GB,那么这种手动排序方法将失败。而且,随着列表规模的不断扩大,这种方法也无法很好地扩展。如果您告诉我们您的用例,我们可能会帮助您找到实现所需的其他方法。该表不是有效的Lua代码,请显示您的真实代码。错误消息告诉您,
wholeList
不是表,而是用户数据。我对Lua不熟悉,这意味着什么?我该怎么解决呢?你需要把它做成一张桌子。你能再解释一下你想要达到的目标吗?如果您使用的是大型有序列表(LDT),它会自动按键排序。如果您的主要用例是按日期列出,为什么不使用时间戳作为毫秒精度的键(不允许重复键)?Aerospike将UDF的执行限制为1GB,因此如果LDT中的UDF超过1GB,那么这种手动排序方法将失败。而且,随着列表规模的不断扩大,这种方法也无法很好地扩展。如果您告诉我们您的用例,我们可能会帮助您找到实现所需的替代方法。
 { code: 100,
 message: '/opt/aerospike/usr/udf/lua/timelines.lua:49: bad argument #1 to \'sort\' (table expected, got userdata)',