title: Spark dataframe slice
body: <p>I've a table with (millions of) entries along the lines of the following example read into a Spark dataframe (<code>sdf</code>):</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>C1</th>
  <th>C2</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>xx1</td>
  <td>c118</td>
  <td>c219</td>
  </tr>
  <tr>
  <td>xx1</td>
  <td>c113</td>
  <td>c218</td>
  </tr>
  <tr>
  <td>xx1</td>
  <td>c118</td>
  <td>c214</td>
  </tr>
  <tr>
  <td>acb</td>
  <td>c121</td>
  <td>c201</td>
  </tr>
  <tr>
  <td>e3d</td>
  <td>c181</td>
  <td>c221</td>
  </tr>
  <tr>
  <td>e3d</td>
  <td>c132</td>
  <td>c252</td>
  </tr>
  <tr>
  <td>abq</td>
  <td>c141</td>
  <td>c290</td>
  </tr>
  <tr>
  <td>...</td>
  <td>...</td>
  <td>...</td>
  </tr>
  <tr>
  <td>vy1</td>
  <td>c13023</td>
  <td>C23021</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I'd like to get a smaller subset of these <em>Id's</em> for further processing. I identify the unique set of <em>Id's</em> in the table using <code>sdf_id = sdf.select(&quot;Id&quot;).dropDuplicates()</code>.</p>
  <p>What is the efficient way from here to filter data (<em>C1</em>, <em>C2</em>) related to, let's say, 100 randomly selected <em>Id's</em>?</p>