{"id":1492,"date":"2017-01-05T20:28:46","date_gmt":"2017-01-05T20:28:46","guid":{"rendered":"http:\/\/62.131.51.129\/?p=1492"},"modified":"2017-01-05T20:28:46","modified_gmt":"2017-01-05T20:28:46","slug":"another-pyspark-scripts","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=1492","title":{"rendered":"Another Pyspark scripts"},"content":{"rendered":"<p>In this note, I show yet another Pyspark with slightly different methods to filter. The idea is that file is read in a RDD. Subsequently, it is cleaned. That cleaning process involves a removal of lines that are too long. The lines are split with a character that is on the twentieth position. Then the lines with a number of elements unequal to 14 are filtered out. After that, some columns are kept. Finally, the values are concatenated into a line and written to disk.<br \/>\nWe have:<\/p>\n<pre>\ndevstatus = sc.textFile(\"\/loudacre\/devicestatus.txt\")\n\n# Filter out lines with < 10 characters, use the 20th character as the delimiter, parse the line, and filter out bad lines\ncleanstatus = devstatus. \\\n    filter(lambda line: len(line) > 20). \\\n    map(lambda line: line.split(line[19:20])). \\\n    filter(lambda values: len(values) == 14)\n    \n\n# Create a new RDD containing date, manufacturer, device ID, latitude and longitude\ndevicedata = cleanstatus. \\\n    map(lambda words: (words[0], words[1].split(' ')[0], words[2], words[12], words[13]))\n\n# Save to a CSV file as a comma-delimited string (trim parenthesis from tuple toString)\ndevicedata. \\\n    map(lambda values: ','.join(values)). \\\n    saveAsTextFile(\"\/loudacre\/devicestatus_etl\")\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this note, I show yet another Pyspark with slightly different methods to filter. The idea is that file is read in a RDD. Subsequently, it is cleaned. That cleaning process involves a removal of lines that are too long. The lines are split with a character that is on the twentieth position. Then the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1493,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1492","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\/1492","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=1492"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1492\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1492"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}