title: How to add a schema to a Dataset in Spark?
body: <p>I am trying to load a file into spark.
  If I load a normal textFile into Spark like below:</p>
  
  <pre><code>val partFile = spark.read.textFile("hdfs://quickstart:8020/user/cloudera/partfile")
  </code></pre>
  
  <p>The outcome is:</p>
  
  <pre><code>partFile: org.apache.spark.sql.Dataset[String] = [value: string]
  </code></pre>
  
  <p>I can see a dataset in the output. But if I load a Json file:</p>
  
  <pre><code>val pfile = spark.read.json("hdfs://quickstart:8020/user/cloudera/pjson")
  </code></pre>
  
  <p>The outcome is a dataframe with a readymade schema:</p>
  
  <pre><code>pfile: org.apache.spark.sql.DataFrame = [address: struct&lt;city: string, state: string&gt;, age: bigint ... 1 more field]
  </code></pre>
  
  <p>The Json/parquet/orc files have schema. So I can understand that this is a feature from Spark version:2x, which made things easier as we directly get a DataFrame in this case and for a normal textFile you get a dataset where there is no schema which makes sense.
  What I'd like to know is how can I add a schema to a dataset that is a resultant of loading a textFile into spark. For an RDD, there is case class/StructType option to add the schema and convert it to a DataFrame. 
  Could anyone let me know how can I do it ?</p>