Skip to content

Instantly share code, notes, and snippets.

@arunthampi
Created August 31, 2009 21:18
Show Gist options
  • Save arunthampi/178718 to your computer and use it in GitHub Desktop.
Save arunthampi/178718 to your computer and use it in GitHub Desktop.
IDT1 = ID of Thread 1, T1 = Thread 1, RT1 = Reply 1 to Thread 1, RT2 = Reply 2 to Thread 1, RT3 = Reply 3 to Thread 1, IDR1 = ID of Reply 1, IDR2 = ID of Reply 2, IDR3 = ID of Reply 3
Remember that the inputs to a reduce function are like so:
Parameter 1: key : Array whose elements are of the form [key, id] where key is the key emitted by the map function and id is the ID of the document from which the key is generated
Parameter 2: values : Array of values returned by previous calls to the reduce function (OR) array of values emitted for respective elements in keys
Parameter 3: rereduce : Can be either true or false
Scenario 1:
Reduce function called like this:
reduce([ [IDT1, IDT1], [IDT1, IDR1], [IDT1, IDR2], [IDT1, IDR3] ], [T1, RT1, RT2, RT3, RT4], false); -> Emits final value
Scenario 2:
Reduce function called multiple times like this:
reduce([IDT1, IDT1], [T1], false) -> Emits Intermediate Value O1 (called with rereduce = false)
reduce([IDT1, IDR1], [RT1], false) -> Emits Intermediate Value O2 (called with rereduce = false)
reduce([IDT1, IDR2], [RT2], false) -> Emits Intermediate Value O3 (called with rereduce = false)
reduce([IDT1, IDR3], [RT3], false) -> Emits Intermediate Value O4 (called with rereduce = false)
and finally
reduce(null, [O1, O2, O3, O4], true) -> Emits final value (called with rereduce = true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment