is it possible to get one result from a map/reduce...
# suitescript
b
is it possible to get one result from a map/reduce script getInputData to map phase
s
Yeah, just pass a single result from the getInput phase, not sure if that is what you mean.
b
that is what I am trying to do but getting this:
s
What am I looking at here?
b
logging from the map phase
s
what are you passing from the getInput?
b
let resultSet = fileSearch.run() resultSet.each(function (result){ seaResult = result; return false; }); return seaResult;
s
Your goal is to just pass the first result from that search, right?
b
yes, that is correct
s
It looks like its interpreting that properties from that object you are passing individually, try return fileSearch.run().getRange(0,1) instead, see if that gives you a better result in the map phase
b
much better
context key 12/03/2020 9:53 am -System- 0 context value 12/03/2020 9:53 am -System- {"recordType":"file","id":"3945945","values":{"name":"SC2020120106.XML"}}
thank you
s
var values = JSON.parse(context.value).values;
, log that and should be good to go
🙏 1
b
if anyone looks back at this context.value contained {"recordType":"file","id":"3945945","values":{"name":"SC2020120106.XML"}} so I was able to get internal id with JSON.parse(context.value).id
s
a more generally useful way to reduce the result set is to add a filter that returns just one result.
assuming that you're only doing the 1 result thing for testing. If you're script truly wants to only process 1 result per execution then I wouldn't use M/R at all 🙂
b
I wanted to use M/R because of yeilding, the file is a very long XML of shipments from our 3PL, I write each shipment to a custom record, I want to be able to use the yeilding from M/R so that if soft governance is an issue then the M/R script will resume
with that requirement would you still not use M/R?
s
The MR won't magically fix anything governance-wise, if you are saying you write each record down to its own reduce stage while interpreting the file in the map, then that makes perfect sense to do that.
b
yes, that is what I am doing
s
Actually, I think M/R has the ability to load the file directly
and pass each line to your map stage
b
I'm not following?
s
I may be wrong on that but I thought I'd done that before
b
got it
s
wait, you say it's an XML file
b
yes sir
s
so the line-oriented behavior of that file support wouldn't apply
b
I'm loading the file in the map phase
converting it to JSON
and then passing the data to create each record in the reduce phase
previously it was a scheduled script but running out of governance because we were getting files with 1000s of shipments
s
I thought MR still has a 10,000 unit limit on
map()
?
b
1000 on map, 5000 on reduce per iteration
soft limit of 10,000
but if it hits 10k it yeild and continues with key/pair
s
The map should be using liek no governance to convert to JSON though, right?
b
correct
s
yeah, design makes sense then to me
b
I'm only using 10 to load the file
s
and your
reduce
will fit in the 5000 limit in any iteration?
b
yes, creating only one custom record per reduce
s
ah, ok so you're emitting thousands of (unique) keys for reduce?
b
potentially yes
s
in effect, you're using reduce as another map (it's reducing a collection of 1 on each invocation)
b
I suppose yes, ideally our 3PL wouldn't send us so many shipment confirmations on one XML but we have to live with it I guess
s
I agree with Sandii that sounds sane enough. sorry to get off topic
b
good discussion
s
though I wouldn't be surprised if the underlying machinery were skewed towards having many
map
instances and relatively fewer
reduce
instances - you've just cleverly turned that around to the opposite, but if it works then it sounds like it's good leveraging of the governance.
s
To stalberts point, you could just convert the file into a JSON in the getInput, and pass the JSON down to the map where each invocation of the map is for each custom record entry.
b
wouldn't I hit the hard limit of 1000 governance on map?
1000 per invocation
I suppose not
if each was only one shipment, hmm
c
Thats the beauty of MR scripts, if you write them correctly, you should never run out of governance and the only answer to "how do we make it faster" is (should be at least) to open the wallet and buy more suitecloud+ licenses.