title: Iterate rows and columns in Spark dataframe
body: <p>I have the following Spark dataframe that is created dynamically:</p>
  
  <pre><code>val sf1 = StructField("name", StringType, nullable = true)
  val sf2 = StructField("sector", StringType, nullable = true)
  val sf3 = StructField("age", IntegerType, nullable = true)
  
  val fields = List(sf1,sf2,sf3)
  val schema = StructType(fields)
  
  val row1 = Row("Andy","aaa",20)
  val row2 = Row("Berta","bbb",30)
  val row3 = Row("Joe","ccc",40)
  
  val data = Seq(row1,row2,row3)
  
  val df = spark.createDataFrame(spark.sparkContext.parallelize(data), schema)
  
  df.createOrReplaceTempView("people")
  val sqlDF = spark.sql("SELECT * FROM people")
  </code></pre>
  
  <p>Now, I need to iterate each row and column in <code>sqlDF</code> to print each column, this is my attempt:</p>
  
  <pre><code>sqlDF.foreach { row =&gt;
    row.foreach { col =&gt; println(col) }
  }
  </code></pre>
  
  <p><code>row</code> is type <code>Row</code>, but is not iterable that's why this code throws a compilation error in <code>row.foreach</code>. How to iterate each column in <code>Row</code>?</p>