Lua udf reduce function seems not excuted

udf

#1

here is my lua udf script

function distance_to(src_lng, src_lat, des_lng, des_lat)
    xSide2 = (src_lat - des_lat) * (src_lat - des_lat);
    ySide2 = (src_lng - des_lng) * (src_lng - des_lng);
    return math.sqrt(xSide2 + ySide2);
end

function split(str, sep)
    local sep, fields = sep or "\t", {}
    local pattern = string.format("([^%s]+)", sep)
    str:gsub(pattern, function(c) fields[#fields+1] = c end)
    return fields
end

local function reduce_stats(a, b)
    local out = map()
    if (a["dis"] > b["dis"]) then
        out["dis"] = b["dis"]
        out["area"] = b["area"]
    else
        out["dis"] = a["dis"]
        out["area"] = a["area"]
    end
    return out
end

local function map_stat(out, rec)
    local src_lng = out['src_lng']
    local src_lat = out['src_lat']
    local nearest_dis = out['dis']
    local current_area_id = rec['areaid']
    local lbs_info = rec['lbs']
    local lbs_fields = split(lbs_info, 'x')
    local des_lng = tonumber(lbs_fields[1])
    local des_lat = tonumber(lbs_fields[2])
    local current_dis = distance_to(src_lng, src_lat, des_lng, des_lat)
    if ( nearest_dis > current_dis ) then
        out['dis'] = current_dis
        out['area'] = current_area_id
    end
    return out
end

function geo_nearest(stream, lng, lat)
    return stream :
    aggregate(map{src_lng = lng, src_lat = lat, area = "", dis = 100}, map_stat) :
    reduce(reduce_stats)
end

which returns a serial of values,not a single one.Is that reduce function didn’t execute on the client node?Need some addtion ops?


#2

See How do I debug the 'reduce()' operation of a stream UDF? and track it all the way through.


#3

tks,I have read this.Btw I’m trying to query geospatial information about nearest place to a given geospatial point using hadoop mapreduce program and async aerospike client api.But performance degrades to around 20TPS.Is there some best practise on geospatial query? thanks a lot.


#4

Perhaps post that as a separate question with different topic - under https://discuss.aerospike.com/c/how-developers-are-using-aerospike/use-cases ? - so folks doing geo-spatial may be able to comment.