title: Converting List of List or RDD to DataFrame in Spark-Scala
body: <p>So basically what I am trying to achieve is - I have a table with 4 columns (say) and I expose it to a DataFrame - DF1. Now I want to store each of the row of the DF1 to another hive table (basically DF2 which schema as - Column1, Column2, Column3) while the column3 value will be the '-' delimited row of DataFrame DF1. </p>
  
  <pre><code>val df = hiveContext.sql("from hive_table SELECT *")
  val writeToHiveDf = df.filter(new Column("id").isNotNull)
  
  var builder : List[(String, String, String)] = Nil
      var finalOne  =  new ListBuffer[List[(String, String, String)]]()
      writeToHiveDf.rdd.collect().foreach {
        row =&gt;
          val item = row.mkString("-@")
          builder = List(List("dummy", "NEVER_NULL_CONSTRAINT", "some alpha")).map{case List(a,b,c) =&gt; (a,b,c)}
          finalOne += builder
      }
  </code></pre>
  
  <p>Now I have the <strong>finalOne</strong> as a list of lists, which I want to convert to a dataframe directly or via RDD. </p>
  
  <pre><code>var listRDD = sc.parallelize(finalOne) //Converts to RDD - It works. 
  val dataFrameForHive : DataFrame = listRDD.toDF("table_name", "constraint_applied", "data") //Doesn't work
  </code></pre>
  
  <p><strong>Error :</strong> </p>
  
  <pre><code>java.lang.ClassCastException: org.apache.spark.sql.types.ArrayType cannot be cast to org.apache.spark.sql.types.StructType
      at org.apache.spark.sql.SQLContext.createDataFrame(SQLContext.scala:414)
      at org.apache.spark.sql.SQLImplicits.rddToDataFrameHolder(SQLImplicits.scala:94)
  </code></pre>
  
  <p>Can some one help me understand the right way to convert this to DataFrame. Thanks a ton in advance for your support.</p>