Question/Observation on MapReduce 'global' variabl...
# suitescript
s
Question/Observation on MapReduce 'global' variables. I used to think you couldn't define a script-global variable and have it survive multiple invocations of
map()
? Years ago I recall it seemed like
map()
was invoked with a new execution context, so that any global variable would be reset. It doesn't seem to be doing that any longer?
d
I ran into this recently actually, it seems "global" vars persist during the same Stages e.g. you could push data to same shared array between multiple map executions, but could not pass array from Input to Map etc.
s
wow, that's a big change, even if only within the 'same stage'
has anyone seen documentation on the behavior of 'script global' variables in MR?
d
typically I would suggest gathering what you can in Input and then passing to each Map etc. to avoid any funky-ness since this doesnt seem to be really documented
but in cases where it is not a simple object that can be stringify/parsed, could see the need to use a global Map var as described
b
looks like each processor has its own global state
although i havent tested it, im guessing, that state will be lost when it yields
c
Why not use N/cache?
global anything is typically a terrible idea
b
finished, testing, yielding does indeed reset the global state
s
N/cache is the typical 'global var simulator' but more complex than just assigning a variabl3e
[script] global variables in most NS scripts is a great idea
@battk good to know
s
Yeah I don't use globals in MR but they definitely did not work before.