title: Spark - Issue with select statement run multiple times
body: <p>Small question regarding Spark please.</p>
  <p>What I would like to achieve is quite straightforward:
  I have a Spark cluster with 10 executors which I would like to utilize.
  I need to run a query selecting 10 rows from the DB.</p>
  <p>My expectation is something like: select 10 rows, results are rows 1 2 3 4 5 6 7 8 9 10.
  Then apply a map operation on each row. Something like executor 1 applies the operation Op to row one of the row, executor 2 applies the operation Op to another row, etc...</p>
  <p>Note, my operation OP have proper logging and proper KPI.</p>
  <p>Therefore, I went to try this:</p>
  <pre><code> public static void main(String[] args) {
          final String query = &quot;SELECT TOP(10) id, last_name, first_name FROM mytable WHERE ...&quot;;
          final SparkSession sparkSession = SparkSession.builder().getOrCreate();
          final Properties   dbConnectionProperties   = new Properties();
          dbConnectionProperties.putAll([...]);
  
          final Dataset&lt;Row&gt; topTenDataSet = sparkSession.read().jdbc(someUrl, query, dbConnectionProperties);
          topTenDataSet.show();
          
          final Dataset&lt;String&gt; topTenDataSetAfterMap = topTenDataSet.repartition(10).map((MapFunction&lt;Row, String&gt;) row -&gt; performOperationWithLogAndKPI(row), Encoders.STRING());
  
          LOGGER.info(&quot;the count is expected to be 10 &quot; + topTenDataSetAfterMap.count() + topTenDataSetAfterMap.showString(100000, 1000000, false));
          sparkSession.stop();
      }
  </code></pre>
  <p>With this code, there is a strange outcome.</p>
  <p>Both <code>topTenDataSet.show();</code> and <code>topTenDataSetAfterMap.count()</code> shows 10 rows, happy.</p>
  <p>But I look at the logs from the operation Op <code>performOperationWithLogAndKPI </code> I can see much more than 10 logs, much more than 10 metrics. Meaning, I can see executor 1 performing 10 times the operation, but also executor 2 performing 10 times the operation, etc.</p>
  <p>It seems like each executor run its own &quot;SELECT TOP(10) from DB&quot; and applies the map function on each dataset.</p>
  <p>May I ask: did I made some mistake in the code?</p>
  <p>Is my understanding not correct?</p>
  <p>How to achieve the expected, querying once, and having each executor apply a function to part of the result set?</p>
  <p>Thank you</p>