Reputation: 1153
I have a nodejs and aerospike set up. I want to know how run a query where Bin1 == Bin2
.
In SQL
SELECT * FROM [test]t where t.EmployeeId == t.shipperid
Can it be done ? I can always query all the values from test
set and filter it in nodejs. However I think it will be highly inefficient. Please let me know if there is an aerospike way to doing it?
Upvotes: 1
Views: 170
Reputation: 7117
This is not supported through the existing query predicates, but you can express this as a stream UDF.
local function bin_match_filter(bin1, bin2)
return function(rec)
if rec[bin1] and rec[bin2] and
(type(rec[bin1]) == type(rec[bin2])) and
rec[bin1] == rec[bin2] then
return true
end
return false
end
end
local function map_record(rec)
local ret = map()
for i, bin_name in ipairs(record.bin_names(rec)) do
ret[bin_name] = rec[bin_name]
end
return ret
end
function check_bins_match(stream, bin1, bin2)
return stream : filter(bin_match_filter(bin1, bin2)) : map(map_record)
end
You can now run the records matched by a secondary index query, or a scan through this stream UDF.
Upvotes: 0
Reputation: 1933
You can create an extra bin, "equal_ids"
, which is set to true when the IDs are equal. This bin is to have a secondary index. Then, you can do a secondary index query for equal_ids==true
Upvotes: 1