blob: d770da5f795de79ad6f5aad86d1bc60c62b35c1e (
plain) (
tree)
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pyspark.files — PySpark master documentation</title>
<link rel="stylesheet" href="../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: 'master',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<link rel="top" title="PySpark master documentation" href="../../index.html" />
<link rel="up" title="Module code" href="../index.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="nav-item nav-item-0"><a href="../../index.html">PySpark master documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for pyspark.files</h1><div class="highlight"><pre>
<span class="c">#</span>
<span class="c"># Licensed to the Apache Software Foundation (ASF) under one or more</span>
<span class="c"># contributor license agreements. See the NOTICE file distributed with</span>
<span class="c"># this work for additional information regarding copyright ownership.</span>
<span class="c"># The ASF licenses this file to You under the Apache License, Version 2.0</span>
<span class="c"># (the "License"); you may not use this file except in compliance with</span>
<span class="c"># the License. You may obtain a copy of the License at</span>
<span class="c">#</span>
<span class="c"># http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c">#</span>
<span class="c"># Unless required by applicable law or agreed to in writing, software</span>
<span class="c"># distributed under the License is distributed on an "AS IS" BASIS,</span>
<span class="c"># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c"># See the License for the specific language governing permissions and</span>
<span class="c"># limitations under the License.</span>
<span class="c">#</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s">'SparkFiles'</span><span class="p">]</span>
<div class="viewcode-block" id="SparkFiles"><a class="viewcode-back" href="../../pyspark.html#pyspark.SparkFiles">[docs]</a><span class="k">class</span> <span class="nc">SparkFiles</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Resolves paths to files added through</span>
<span class="sd"> L{SparkContext.addFile()<pyspark.context.SparkContext.addFile>}.</span>
<span class="sd"> SparkFiles contains only classmethods; users should not create SparkFiles</span>
<span class="sd"> instances.</span>
<span class="sd"> """</span>
<span class="n">_root_directory</span> <span class="o">=</span> <span class="bp">None</span>
<span class="n">_is_running_on_worker</span> <span class="o">=</span> <span class="bp">False</span>
<span class="n">_sc</span> <span class="o">=</span> <span class="bp">None</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s">"Do not construct SparkFiles objects"</span><span class="p">)</span>
<span class="nd">@classmethod</span>
<div class="viewcode-block" id="SparkFiles.get"><a class="viewcode-back" href="../../pyspark.html#pyspark.SparkFiles.get">[docs]</a> <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Get the absolute path of a file added through C{SparkContext.addFile()}.</span>
<span class="sd"> """</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">SparkFiles</span><span class="o">.</span><span class="n">getRootDirectory</span><span class="p">(),</span> <span class="n">filename</span><span class="p">)</span>
<span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</div>
<span class="nd">@classmethod</span>
<div class="viewcode-block" id="SparkFiles.getRootDirectory"><a class="viewcode-back" href="../../pyspark.html#pyspark.SparkFiles.getRootDirectory">[docs]</a> <span class="k">def</span> <span class="nf">getRootDirectory</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Get the root directory that contains files added through</span>
<span class="sd"> C{SparkContext.addFile()}.</span>
<span class="sd"> """</span>
<span class="k">if</span> <span class="n">cls</span><span class="o">.</span><span class="n">_is_running_on_worker</span><span class="p">:</span>
<span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">_root_directory</span>
<span class="k">else</span><span class="p">:</span>
<span class="c"># This will have to change if we support multiple SparkContexts:</span>
<span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">_sc</span><span class="o">.</span><span class="n">_jvm</span><span class="o">.</span><span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">spark</span><span class="o">.</span><span class="n">SparkFiles</span><span class="o">.</span><span class="n">getRootDirectory</span><span class="p">()</span></div></div>
</pre></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../index.html">
<img class="logo" src="../../_static/spark-logo-hd.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="nav-item nav-item-0"><a href="../../index.html">PySpark master documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright .
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
</div>
</body>
</html>
|