如何为范围查询编写 Aerospike 流 UDF
How to write an Aerospike stream UDF for a range Query
我为范围查询编写了流 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>;
Java 调用此 lua 函数的代码:
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)
-- 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
知道如何为所有查询限制编写过滤器吗?
谢谢!
不支持多个聚合函数。必须结合聚合和过滤功能。
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
因为 release 3.12 a predicate filter 是正确的方法,完全避免 Lua 以获得更好的性能和可扩展性。
看看 PredExp class of the Java client and its examples for building complex filters. Predicate filtering also currently exists for the C, C# and Go 个客户。
我为范围查询编写了流 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>;
Java 调用此 lua 函数的代码:
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)
-- 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
知道如何为所有查询限制编写过滤器吗?
谢谢!
不支持多个聚合函数。必须结合聚合和过滤功能。
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
因为 release 3.12 a predicate filter 是正确的方法,完全避免 Lua 以获得更好的性能和可扩展性。
看看 PredExp class of the Java client and its examples for building complex filters. Predicate filtering also currently exists for the C, C# and Go 个客户。