2015-02-05 13 views
1

나는 다음과 같은 구조 쓰레기통에 aerospike 설정 : 나는 다음 쓰기를 시도Aerospike 그룹으로

SELECT item, sum(qty), sum(price), sum(discount) 
FROM items 
WHERE timestamp between 20150101000000 and 201501GROUP BY item 

해당 SQL 다음 달성하기 위해 노력하고있어

항목, 타임 스탬프, 수량, 가격, 할인 루아 스크립트 그러나 스크립트를 실행하는 동안 오류 다음 얻을

Error: (1) AEROSPIKE_ERR_SERVER : "UDF: Execution Error 2 : /opt/aerospike /usr/udf/lua/aggregateByItem.lua:21: attempt to index a nil value"

수있는이

해결에 누군가의 도움 451,515,
local function aggregate_item_stats(itemMap,rec) 
    local item = rec.item 
    local innerMap = itemMap[item] 
    if innerMap == nil then 
     innerMap = {qty = 0, price = 0, discount = 0} 
    end 
    innerMap.qty = innerMap.qty + (tonumber(rec.qty) or 0); 
    innerMap.price = innerMap.price + (tonumber(rec.price) or 0); 
    innerMap.discount = innerMap.discount + (tonumber(rec.discount) or 0); 
    itemMap[item] = innerMap 
    return itemMap 
end 

local function fn_merge(a,b) 
    a.qty = a.qty + b.qty 
    a.price = a.price + b.price 
    a.discount = a.discount + b.discount 
    return a 
end 
local function reduce_values(a, b) 
    return map.merge(a, b, fn_merge) 
end 
function highUsageReport(stream) 
return stream : aggregate(itemMap{}, aggregate_item_stats) : reduce(reduce_values) 
end 
+0

위의 오류 외에도 udf에 대한 디버깅을 활성화 한 후 다음 오류가 발생합니다. '오류 : (1) AEROSPIKE_ERR_SERVER : "UDF : 실행 오류 2 : /opt/aerospike/sys/udf/lua/stream_ops.lua:175 : upvalue 'f'(nil 값) 호출 시도 " ' – tabreaz

답변

1

는 주요 변화는 행에서 인 작동 코드 4

경우 innerMap 전무 == 다음

에 innerMap == null이 다음

local function aggregate_item_stats(itemMap, rec) 
local key = rec.item 
local innerMap = itemMap[key] 
if innerMap == null then 
    innerMap = map {qty = 0, price = 0, discount = 0} 
end 
innerMap.qty = (tonumber(rec.qty) or 0) 
innerMap.price = innerMap.price + tonumber(rec.price or 0) 
innerMap.discount = innerMap.discount + tonumber(rec.discount or 0) 
itemMap[key] = innerMap 
return itemMap 
end 

local function reduce_values(a, b) 
return map.merge(a, b, fn_merge) 
end 

local function fn_merge(a, b) 
a.qty = tonumber(a.qty) + tonumber(b.qty) 
a.price = tonumber(a.price) + tonumber(b.price) 
a.discount = tonumber(a.discount) + tonumber(b.discount) 
return a 
end 

function highUsageReport(stream) 
return stream : aggregate(map(), aggregate_item_stats) 
    : reduce(reduce_values) 
end 
경우