我为一个范围查询编写了一个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 Script:
local function map_links(record)
-- Add user and password to returned map.
-- Could add other record bins here as well.
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
知道如何为所有查询限制编写过滤器吗?
谢谢!
答案 0 :(得分:1)
不支持多个聚合功能。必须合并聚合和过滤功能。
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
答案 1 :(得分:1)