title: Spark Dataset Foreach function does not iterate
body: <p><strong>Context</strong></p>
  <p>I want to iterate over a <a href="https://spark.apache.org/docs/2.1.1/api/java/index.html?org/apache/spark/sql/Dataset.html" rel="nofollow noreferrer">Spark Dataset</a> and update a HashMap for each row.</p>
  <p>Here is the code I have:</p>
  <pre><code>// At this point, I have a my_dataset variable containing 300 000 rows and 10 columns
  // - my_dataset.count() == 300 000
  // - my_dataset.columns().length == 10
  
  // Declare my HashMap
  HashMap&lt;String, Vector&lt;String&gt;&gt; my_map = new HashMap&lt;String, Vector&lt;String&gt;&gt;();
  
  // Initialize the map
  for(String col : my_dataset.columns())
  {
      my_map.put(col, new Vector&lt;String&gt;());
  }
  
  // Iterate over the dataset and update the map
  my_dataset.foreach( (ForeachFunction&lt;Row&gt;) row -&gt; {
      for(String col : my_map.KeySet())
      {
          my_map.get(col).add(row.get(row.fieldIndex(col)).toString());
      }
  });
  </code></pre>
  <p><strong>Issue</strong></p>
  <p>My issue is that the foreach doesn't iterate at all, the lambda is never executed and I don't know why.<br/>
  I implemented it as indicated here: <a href="https://stackoverflow.com/a/42757659">How to traverse/iterate a Dataset in Spark Java?</a></p>
  <p>At the end, all the inner Vectors remain empty (as they were initialized) despite the Dataset is not (Take a look to the first comments in the given code sample).</p>
  <p>I know that the foreach never iterates because I did two tests:</p>
  <ul>
  <li>Add an <code>AtomicInteger</code> to count the iterations, increment it right in the beginning of the lambda with <code>incrementAndGet()</code> method. =&gt; The counter value remains <code>0</code> at the end of the process.</li>
  <li>Print a debug message right in the beginning of the lambda. =&gt; The message is never displayed.</li>
  </ul>
  <p><em>I'm not used of Java (even less with Java lambdas) so maybe I missed an important point but I can't find what.</em></p>