title: How to get a value from Dataset and store it in a Scala value?
body: <p>I have a dataframe which looks like this:</p>
  
  <pre><code>scala&gt; avgsessiontime.show()
  +-----------------+
  |              avg|
  +-----------------+
  |2.073455735838315|
  +-----------------+
  </code></pre>
  
  <p>I need to store the value 2.073455735838315 in a variable. I tried using </p>
  
  <pre><code>avgsessiontime.collect 
  </code></pre>
  
  <p>but that starts giving me <strong>Task not serializable exceptions</strong>. So to avoid that I started using foreachPrtition. But I dont know how to extract the value 2.073455735838315 in an array variable.</p>
  
  <pre><code>scala&gt; avgsessiontime.foreachPartition(x =&gt; x.foreach(println))
  [2.073455735838315]
  </code></pre>
  
  <p>But when I do this:</p>
  
  <pre><code>avgsessiontime.foreachPartition(x =&gt; for (name &lt;- x) name.get(0))
  </code></pre>
  
  <p>I get a blank/empty result. Even the length returns empty.</p>
  
  <pre><code>avgsessiontime.foreachPartition(x =&gt; for (name &lt;- x) name.length)
  </code></pre>
  
  <p>I know name is of type org.apache.spark.sql.Row then it should return both those results. </p>