2016-11-28 12 views
1

범위 쿼리에 대해 스트림 UDF를 작성했지만 제대로 작동하지 않습니다. 루아로 많은 필터를 설정하는 방법을 알고 계신가요? 범위에 대한 Aerospike 스트림 UDF 작성 방법 쿼리

쿼리 :

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)); 

루아 스크립트 :

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 

어떤 생각이 어떻게 모든 쿼리에 대한 필터를 작성하는 방법이 루아 함수를 호출하는

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>; 

자바 코드 제한 사항?

감사합니다.

+0

동시에 다음 사이트에서 논의됩니다. https://discuss.aerospike.com/t/record-manipulation-with-more-than-one-filter-lua/3637 – pgupta

답변

1

release 3.12 있기 때문에 predicate filter은 올바른 방법이 될 것입니다 더 나은 성능과 확장 성을 완전히 루아를 피하는.

Java 클라이언트의 PredExp 클래스와 복합 필터 작성을위한 examples 클래스를 살펴보십시오. 현재 술어 필터링은 C, C#Go 클라이언트에도 있습니다.

+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