title: What is the efficient way to create schema for a dataframe?
body: <p>I am new to spark and I saw that there are two ways to create a data frame's schema.
  I have an RDD: empRDD with data(split by ",")</p>
  
  <pre><code>+---+-------+------+-----+
  |  1|   Mark|  1000|   HR|
  |  2|  Peter|  1200|SALES|
  |  3|  Henry|  1500|   HR|
  |  4|   Adam|  2000|   IT|
  |  5|  Steve|  2500|   IT|
  |  6|  Brian|  2700|   IT|
  |  7|Michael|  3000|   HR|
  |  8|  Steve| 10000|SALES|
  |  9|  Peter|  7000|   HR|
  | 10|    Dan|  6000|   BS|
  +---+-------+------+-----+
  
  val empFile = sc.textFile("emp")
  val empData = empFile.map(e =&gt; e.split(","))
  </code></pre>
  
  <p>First way to create schema is using a case class:</p>
  
  <pre><code>case class employee(id:Int, name:String, salary:Int, dept:String)
  val empRDD = empData.map(e =&gt; employee(e(0).toInt, e(1), e(2).toInt, e(3)))
  val empDF = empRDD.toDF()
  </code></pre>
  
  <p>Second way is using StructType:</p>
  
  <pre><code>    val empSchema = StructType(Array(StructField("id", IntegerType, true),
                      StructField("name", StringType, true), 
                      StructField("salary", IntegerType, true), 
                      StructField("dept", StringType, true)))
      val empRDD = empdata.map(e =&gt; Row(e(0).toInt, e(1), e(2).toInt, e(3)))
      val empDF  = sqlContext.createDataFrame(empRDD, empSchema)
  </code></pre>
  
  <p>Personally I prefer to code using StructType. But I don't know which way is recommended in the actual industry projects. Could anyone let me know the preferred way ?</p>