title: How to match Dataframe column names to Scala case class attributes?
body: <p>The column names in this example from spark-sql come from the <code>case class Person</code>.</p>
  
  <pre><code>case class Person(name: String, age: Int)
  
  val people: RDD[Person] = ... // An RDD of case class objects, from the previous example.
  
  // The RDD is implicitly converted to a SchemaRDD by createSchemaRDD, allowing it to be stored using Parquet.
  people.saveAsParquetFile("people.parquet")
  </code></pre>
  
  <p><a href="https://spark.apache.org/docs/1.1.0/sql-programming-guide.html" rel="noreferrer">https://spark.apache.org/docs/1.1.0/sql-programming-guide.html</a></p>
  
  <p>However in many cases the parameter names may be changed.  This would cause columns to not be found if the file has not been updated to reflect the change.</p>
  
  <p><strong>How can I specify an appropriate mapping?</strong></p>
  
  <p>I am thinking something like:</p>
  
  <pre><code>  val schema = StructType(Seq(
      StructField("name", StringType, nullable = false),
      StructField("age", IntegerType, nullable = false)
    ))
  
  
    val ps: Seq[Person] = ???
  
    val personRDD = sc.parallelize(ps)
  
    // Apply the schema to the RDD.
    val personDF: DataFrame = sqlContext.createDataFrame(personRDD, schema)
  </code></pre>