Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 1006 Bytes

delete_keys.textile

File metadata and controls

41 lines (30 loc) · 1006 Bytes

Reduce Phase to Delete Bucket/Key Pairs

[[Source File on GitHub|https://github.com/basho/riak_function_contrib/blob/master/mapreduce/erlang/delete_key.erl]]

This Erlang reduce function will delete bucket and key pairs passed to it from a map phase. The result of the function is the number of keys deleted during the reduce phase.

```erlang
-module(reduce_functions).

-export([delete/2]).

% Data is a list of bucket and key pairs, intermixed with the counts of deleted
% objects. Returns a count of deleted objects.
delete(List, None) →
{ok, C} = riak:local
client(),

Delete = fun(Bucket, Key) → case C:delete(Bucket, Key, 0) of ok → 1; _ → 0 end end, F = fun(Elem, Acc) → case Elem of {{Bucket, Key}, _KeyData} → Acc + Delete(Bucket, Key); {Bucket, Key} → Acc + Delete(Bucket, Key); [Bucket, Key] → Acc + Delete(Bucket, Key); _ → Acc + Elem end end, [lists:foldl(F, 0, List)]

```