{"id":1475,"date":"2017-01-03T13:26:01","date_gmt":"2017-01-03T13:26:01","guid":{"rendered":"http:\/\/62.131.51.129\/?p=1475"},"modified":"2017-01-03T13:26:01","modified_gmt":"2017-01-03T13:26:01","slug":"the-1000th-wordcount-example","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=1475","title":{"rendered":"The 1000th wordcount example"},"content":{"rendered":"<p>I just discovered the 1000th wordcount example. It is based on Pyspark. The idea is actually quite simple. One creates a script. This script can be written in any editor. The programme can then be run from the terminal by spark-submit [programme]. As an example, one may start the programme below with: spark-submit &#8211;master yarn-cluster prog1.py \/user\/hdfs\/fam \/user\/hdfs\/prog1A. The option &#8211;master yarn-cluster indicates how the programme is run. In this case the cluster is used. It can also be run locally; in that case &#8211;master local is used.<\/p>\n<pre>\nimport sys\nfrom pyspark import SparkContext\nif __name__ == \"__main__\":\n    if len(sys.argv) &lt; 3:\n        print &gt;&gt; sys.stderr, \"Usage: WordCount &lt;file&gt;\"\n        exit(-1)\nsc = SparkContext()\ncounts = sc.textFile(sys.argv[1]) \\\n.flatMap(lambda line: line.split(',')) \\\n.map(lambda word: (word,1)) \\\n.reduceByKey(lambda v1,v2: v1+v2)\ncounts.saveAsTextFile(sys.argv[2])\nsc.stop()\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I just discovered the 1000th wordcount example. It is based on Pyspark. The idea is actually quite simple. One creates a script. This script can be written in any editor. The programme can then be run from the terminal by spark-submit [programme]. As an example, one may start the programme below with: spark-submit &#8211;master yarn-cluster [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1476,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1475","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1475"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1475\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1475"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}