merge()

After the accumulate phase completes, the merge method is then used to merge all of the states generated by the accumulate method together into a final state for each group of data. If the merge method returns null, the current values stored in the UDA state variables are not updated.

An analytic UDA (example: select myuda(product_id) over (partition by customer) from sales]) does not call the merge method. Merge is only called for a UDA when the UDA is used in the context of a GROUP BY statement.

Example
function merge(state1,state2)
state1[1] = state1[1] + state2[1]
state1[2] = state1[2] + state2[2]
return state1

end