You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<pclass="shortcomment cmt">Map an RDD to the same type, by applying a partial function and the
384
-
identity otherwise.</p><divclass="fullcomment"><divclass="comment cmt"><p>Map an RDD to the same type, by applying a partial function and the
385
-
identity otherwise.</p><p>Avoids having <codestyle="background-color:#eff0f1;padding:1px 5px;font-size:12px">case x => x</code>.</p><p>Similar idea to <codestyle="background-color:#eff0f1;padding:1px 5px;font-size:12px">.collect</code>,
386
-
but instead of skipping non-matching items, it keeps them as-is.</p><pre>sc.parallelize(<spanclass="std">Array</span>(<spanclass="num">1</span>, <spanclass="num">3</span>, <spanclass="num">2</span>, <spanclass="num">7</span>, <spanclass="num">8</span>)).partialMap { <spanclass="kw">case</span> a <spanclass="kw">if</span> a % <spanclass="num">2</span> == <spanclass="num">0</span><spanclass="kw">=></span><spanclass="num">2</span> * a }
<spanclass="kw">case</span> a <spanclass="kw">if</span> a % <spanclass="num">2</span> == <spanclass="num">0</span><spanclass="kw">=></span><spanclass="num">2</span> * a
390
-
<spanclass="kw">case</span> a <spanclass="kw">=></span> a
391
-
}
392
-
<spanclass="cmt">// in order to map to:</span>
393
-
sc.parallelize(<spanclass="std">Array</span>(<spanclass="num">1</span>, <spanclass="num">3</span>, <spanclass="num">4</span>, <spanclass="num">7</span>, <spanclass="num">16</span>))</pre></div><dlclass="paramcmts block"><dtclass="param">pf</dt><ddclass="cmt"><p>the partial function to apply</p></dd><dt>returns</dt><ddclass="cmt"><p>an rdd of the same type, for which each element is either the
394
-
application of the partial function where defined or the identity.</p></dd></dl></div>
<pclass="shortcomment cmt">Map an RDD to the same type, by applying a partial function and the
435
+
identity otherwise.</p><divclass="fullcomment"><divclass="comment cmt"><p>Map an RDD to the same type, by applying a partial function and the
436
+
identity otherwise.</p><p>Avoids having <codestyle="background-color:#eff0f1;padding:1px 5px;font-size:12px">case x => x</code>.</p><p>Similar idea to <codestyle="background-color:#eff0f1;padding:1px 5px;font-size:12px">.collect</code>,
437
+
but instead of skipping non-matching items, it keeps them as-is.</p><pre>sc.parallelize(<spanclass="std">Array</span>(<spanclass="num">1</span>, <spanclass="num">3</span>, <spanclass="num">2</span>, <spanclass="num">7</span>, <spanclass="num">8</span>)).update { <spanclass="kw">case</span> a <spanclass="kw">if</span> a % <spanclass="num">2</span> == <spanclass="num">0</span><spanclass="kw">=></span><spanclass="num">2</span> * a }
<spanclass="kw">case</span> a <spanclass="kw">if</span> a % <spanclass="num">2</span> == <spanclass="num">0</span><spanclass="kw">=></span><spanclass="num">2</span> * a
441
+
<spanclass="kw">case</span> a <spanclass="kw">=></span> a
442
+
}
443
+
<spanclass="cmt">// in order to map to:</span>
444
+
sc.parallelize(<spanclass="std">Array</span>(<spanclass="num">1</span>, <spanclass="num">3</span>, <spanclass="num">4</span>, <spanclass="num">7</span>, <spanclass="num">16</span>))</pre></div><dlclass="paramcmts block"><dtclass="param">pf</dt><ddclass="cmt"><p>the partial function to apply</p></dd><dt>returns</dt><ddclass="cmt"><p>an rdd of the same type, for which each element is either the
445
+
application of the partial function where defined or the identity.</p></dd></dl></div>
<pclass="shortcomment cmt">Map an RDD of A to an RDD of (B, A) where B is determined from A.</p><divclass="fullcomment"><divclass="comment cmt"><p>Map an RDD of A to an RDD of (B, A) where B is determined from A.</p><p>Replaces for example <codestyle="background-color:#eff0f1;padding:1px 5px;font-size:12px">rdd.map(x => (x.smthg, x))</code>
532
-
with <codestyle="background-color:#eff0f1;padding:1px 5px;font-size:12px">rdd.withKey(_.smthg)</code>.</p><pre>RDD((<spanclass="num">1</span>, <spanclass="lit">"a"</span>), (<spanclass="num">2</span>, <spanclass="lit">"b"</span>)).withKey(_._1) <spanclass="cmt">// RDD(1, (1, "a")), (2, (2, "b"))</span></pre></div><dlclass="paramcmts block"><dtclass="param">toKey</dt><ddclass="cmt"><p>the function to apply to extract the key</p></dd><dt>returns</dt><ddclass="cmt"><p>an rdd of (K, V) from an RDD of V where K is determined by
532
+
with <codestyle="background-color:#eff0f1;padding:1px 5px;font-size:12px">rdd.withKey(_.smthg)</code>.</p><pre>RDD((<spanclass="num">1</span>, <spanclass="lit">"a"</span>), (<spanclass="num">2</span>, <spanclass="lit">"b"</span>)).withKey(_._1) <spanclass="cmt">// RDD(1, (1, "a")), (2, (2, "b"))</span></pre></div><dlclass="paramcmts block"><dtclass="param">toKey</dt><ddclass="cmt"><p>the function to apply to extract the key</p></dd><dt>returns</dt><ddclass="cmt"><p>an RDD of (K, V) from an RDD of V where K is determined by
<spanclass="cmt">// Concept mapper (the following example transforms RDD(1, 3, 2, 7, 8) into RDD(1, 3, 4, 7, 16)):</span>
81
-
rdd.partialMap { <spanclass="kw">case</span> a <spanclass="kw">if</span> a % <spanclass="num">2</span> == <spanclass="num">0</span><spanclass="kw">=></span><spanclass="num">2</span> * a }
81
+
rdd.update { <spanclass="kw">case</span> a <spanclass="kw">if</span> a % <spanclass="num">2</span> == <spanclass="num">0</span><spanclass="kw">=></span><spanclass="num">2</span> * a }
82
82
83
83
<spanclass="cmt">// For when input files contain commas and textFile can't handle it:</span>
<spanclass="cmt">// Concept mapper (the following example transforms RDD(1, 3, 2, 7, 8) into RDD(1, 3, 4, 7, 16)):</span>
335
-
rdd.partialMap { <spanclass="kw">case</span> a <spanclass="kw">if</span> a % <spanclass="num">2</span> == <spanclass="num">0</span><spanclass="kw">=></span><spanclass="num">2</span> * a }
335
+
rdd.update { <spanclass="kw">case</span> a <spanclass="kw">if</span> a % <spanclass="num">2</span> == <spanclass="num">0</span><spanclass="kw">=></span><spanclass="num">2</span> * a }
336
336
337
337
<spanclass="cmt">// For when input files contain commas and textFile can't handle it:</span>
0 commit comments