{"id":1563,"date":"2016-09-10T02:31:31","date_gmt":"2016-09-10T02:31:31","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1563"},"modified":"2016-09-10T02:31:31","modified_gmt":"2016-09-10T02:31:31","slug":"passing-values-in-command-context","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/passing-values-in-command-context\/","title":{"rendered":"Passing Values in Command Context"},"content":{"rendered":"<p><strong>Passing Parameters in Command Context<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AvgStockVolPerMonthMapper extends Mapper&lt;LongWritable, Text, TextPair, LongPair&gt; {\r\n\r\n\tprivate static NYSEParser parser = new NYSEParser();\r\n\tprivate static TextPair mapOutputKey = new TextPair();\r\n\tprivate static LongPair mapOutputValue = new LongPair();\r\n\r\n\tprivate static Set&lt;String&gt; stockTickers = new HashSet&lt;String&gt;();\r\n\r\n\tprotected void setup(Context context) throws IOException, InterruptedException {\r\n\t\tString stockTicker = context.getConfiguration().get(&quot;filter.by.stock&quot;);\r\n\t\tif (stockTicker != null) {\r\n\t\t\tString&#x5B;] tickers = stockTicker.split(&quot;,&quot;);\r\n\r\n\t\t\tfor (String ticker : tickers) {\r\n\t\t\t\tstockTickers.add(ticker);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void map(LongWritable lineOffset, Text record, Context context) throws IOException, InterruptedException {\r\n\t\tparser.parse(record.toString());\r\n\r\n\t\tif (stockTickers.isEmpty() || (!stockTickers.isEmpty() &amp;&amp; stockTickers.contains(parser.getStockTicker()))) {\r\n\t\t\t\r\n\t\t\tif(parser.getStockTicker().equals(&quot;AAN&quot;)|| parser.getStockTicker().equals(&quot;AEB&quot;)|| parser.getStockTicker().equals(&quot;TCB&quot;)|| parser.getStockTicker().equals(&quot;XAA&quot;))\r\n\t\t\t{\r\n\t\t\t\tmapOutputKey.setFirst(new Text(parser.getTradeMonth()));\r\n\t\t\t\tmapOutputKey.setSecond(new Text(parser.getStockTicker()));\r\n\t\r\n\t\t\t\tmapOutputValue.setFirst(new LongWritable(parser.getVolume()));\r\n\t\t\t\tmapOutputValue.setSecond(new LongWritable(1));\r\n\t\t\t\t\r\n\t\t\t\tcontext.write(mapOutputKey, mapOutputValue);\r\n\t\t\t}\t\t\t\r\n\t\t}\r\n\t}\r\n\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Passing Parameters in Command Context public class AvgStockVolPerMonthMapper extends Mapper&lt;LongWritable, Text, TextPair, LongPair&gt; { private static NYSEParser parser = new NYSEParser(); private static TextPair mapOutputKey = new TextPair(); private static LongPair mapOutputValue = new LongPair(); private static Set&lt;String&gt; stockTickers = new HashSet&lt;String&gt;(); protected void setup(Context context) throws IOException, InterruptedException { String stockTicker = context.getConfiguration().get(&quot;filter.by.stock&quot;); if&hellip; <a href=\"https:\/\/codethataint.com\/blog\/passing-values-in-command-context\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[150],"tags":[],"class_list":["post-1563","post","type-post","status-publish","format-standard","hentry","category-map-reduce"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1563"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1563\/revisions"}],"predecessor-version":[{"id":1564,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1563\/revisions\/1564"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}