如何编写用于范围查询的Aerospike流UDF

我编写了一个用于范围查询的Stream UDF,但它无法正常工作。你有没有想法如何用lua设置多个过滤器?

查询语句:

SELECT id1,id2,link_type,visibility,data,time,version FROM linktable
WHERE id1 = <id1> AND
  link_type = <link_type> AND
  time >= <minTime> AND
  time <= <maxTimestamp> AND
  visibility = VISIBILITY_DEFAULT
ORDER BY time DESC LIMIT <offset><limit>;

调用此lua函数的Java代码:

stmt = new Statement();
stmt.setNamespace(dbid);
stmt.setSetName("links");
stmt.setIndexName("time");
stmt.setFilters(Filter.range("time",minTimestamp,maxTimestamp));
stmt.setAggregateFunction("linkbench""check_id1",Value.get(id1));
stmt.setAggregateFunction("linkbench""check_linktype",Value.get(link_type));
resultSet = client.queryAggregate(null,stmt,"linkbench""check_visibility",Value.get(VISIBILITY_DEFAULT));

Lua脚本:

local function map_links(record)
    -- 添加用户和密码到返回的map中。
    -- 还可以在此处添加其他记录bins。
    return record.id2
end

function check_id1(stream,id1)
    local function filter_id1(record)
        return record.id1 == id1
    end
    return stream : filter(filter_id1) : map(map_links)
end

function check_linktype(stream,link_type)
    local function filter_linktype(record)
        return record.link_type == link_type
    end
    return stream : filter(filter_linktype) : map(map_links)
end

function check_visibility(stream,visibility)
    local function filter_visibility(record)
        return record.visibility == visibility
    end
    return stream : filter(filter_visibility) : map(map_links)
end

有没有想法如何编写所有查询限制的过滤器?

谢谢!

点赞
用户5890771
用户5890771

多个聚合函数不受支持。必须组合聚合和过滤函数。

function combined_aggregation(stream,id1,link_type,visibility)
    local function combined_filter(record)
        return record.id1 == id1 and
               record.link_type == link_type and
               record.visibility == visibility
    end
    return stream : filter(combined_filter) : map(map_links)
end
2016-12-13 00:32:52
用户582436
用户582436

版本3.12以来,谓词过滤器是正确的方法,完全避免了Lua,从而获得更好的性能和可扩展性。

查看Java客户端的PredExp类及其示例以构建复杂过滤器。目前谓词过滤器也适用于CC#Go客户端。

2017-07-15 03:16:27