Hi all, In my Map/Reduce script i have a global va...
# suitescript
s
Hi all, In my Map/Reduce script i have a global variable (processedJSONAry) defined which stores the array of JSON values from all the Reduce phased that have been processed. I use this variable "processedJSONAry" in Summarize phase, but over the time i see the value is getting replaced with newly processed data by the Reduce. Can someone help me with understanding the issue. Is there any storage limit for the global array defined? For eg: Initially : processedJSONAry=[{id1,name'a'},{id2,name'b'},{id3,name'c'}......]; after few Reduce runs, the variable is replaced processedJSONAry= [{id26,name'z'}];
n
Why not just write them out in the return of the reduce step? If you write different values to the same key it will not overwrite the value it will understand you're creating an array of values which you can then pick up in the summary...
s
@NElliott: I have my script wrtting the values from Reduce stage. For each key (record internal id), i have a array of JSON. Anyhow, i figured out the issue that, my script triggered the Reduce Stage Thrice and each time the new Reduce Stage (instanse) was triggered the global variable was reset. Hence the issue.
s
You can't use global variables to store information in a map/reduce, you need to change your approach.
e
Yeah this is just what
context.write()
from the
reduce
stage is for. Then you can iterate through
context.output
from the
summarize
stage