title: Iterating on org.apache.spark.sql.Row
body: <p>I'm using Spark shell (1.3.1) which is a Scala shell. The simplified situation that needs iteration on <code>Row</code> is something like this:</p>
  
  <pre><code>import org.apache.commons.lang.StringEscapeUtils
  
  var result = sqlContext.sql("....")
  var rows = result.collect() // Array[org.apache.spark.sql.Row]
  var row = rows(0) // org.apache.spark.sql.Row
  var line = row.map(cell =&gt; StringEscapeUtils.escapeCsv(cell)).mkString(",")
  // error: value map is not a member of org.apache.spark.sql.Row
  println(line)
  </code></pre>
  
  <p>My problem is that <code>Row</code> does not have <code>map</code> and - as far as I know - it cannot be converted to <code>Array</code> or <code>List</code>, so I cannot escape each cell using this style. I could write a loop using an index variable but it would be inconvenient. I would like to iterate on the cells in a situation like this:</p>
  
  <pre><code>result.collect().map(row =&gt; row.map(cell =&gt; StringEscapeUtils.escapeCsv(cell)).mkString(",")).mkString("\n")
  </code></pre>
  
  <p>(These are typically not large results, they can fit into the client memory many times.)</p>
  
  <p>Is there any way to iterate on the cells of a <code>Row</code>? Is there any syntax for putting an index based loop at the place of <code>row.map(...)</code> in the last snippet?</p>