{"id":3453,"date":"2021-07-26T07:08:04","date_gmt":"2021-07-26T07:08:04","guid":{"rendered":"https:\/\/www.bearloga.space\/?page_id=3453"},"modified":"2021-07-26T07:08:04","modified_gmt":"2021-07-26T07:08:04","slug":"pyspark-sparkfiles","status":"publish","type":"page","link":"https:\/\/www.bearloga.space\/en\/pyspark-sparkfiles\/","title":{"rendered":"PySpark \u2014 SparkFiles"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u0412 Apache Spark \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0444\u0430\u0439\u043b\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<strong>sc.addFile<\/strong>&nbsp;(sc \u2014 \u0432\u0430\u0448 SparkContext \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e) \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;<strong>SparkFiles.get<\/strong>&nbsp;.&nbsp;\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, SparkFiles \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0443\u0442\u0438 \u043a \u0444\u0430\u0439\u043b\u0430\u043c, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c \u0447\u0435\u0440\u0435\u0437&nbsp;<strong>SparkContext.addFile ()<\/strong>&nbsp;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SparkFiles \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u2014<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c (\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430)<\/li><li>getrootdirectory ()<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0438\u0445 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c (\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u041e\u043d \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 SparkContext.addFile ().<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">getrootdirectory ()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u041e\u043d \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u043a \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c\u0443 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 SparkContext.addFile ().<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">----------------------------------------sparkfile.py------------------------------------\nfrom pyspark import SparkContext\nfrom pyspark import SparkFiles\nfinddistance = \"\/home\/hadoop\/examples_pyspark\/finddistance.R\"\nfinddistancename = \"finddistance.R\"\nsc = SparkContext(\"local\", \"SparkFile App\")\nsc.addFile(finddistance)\nprint \"Absolute Path -&gt; %s\" % SparkFiles.get(finddistancename)\n----------------------------------------sparkfile.py------------------------------------\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u041a\u043e\u043c\u0430\u043d\u0434\u0430<\/strong>&nbsp;\u2014 \u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$SPARK_HOME\/bin\/spark-submit sparkfiles.py<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 Apache Spark \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0444\u0430\u0439\u043b\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e&nbsp;sc.addFile&nbsp;(sc \u2014 \u0432\u0430\u0448 SparkContext \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e) \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u0443 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[111],"tags":[],"class_list":["post-3453","page","type-page","status-publish","hentry","category-pyspark"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/3453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/comments?post=3453"}],"version-history":[{"count":0,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/3453\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/media?parent=3453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/categories?post=3453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/tags?post=3453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}