title: How to pass schema to create a new Dataframe from existing Dataframe?
body: <p>To pass schema to a json file we do this:                  </p>
  
  <pre><code>from pyspark.sql.types import (StructField, StringType, StructType, IntegerType)
  data_schema = [StructField('age', IntegerType(), True), StructField('name', StringType(), True)]
  final_struc = StructType(fields = data_schema)
  df =spark.read.json('people.json', schema=final_struc)
  </code></pre>
  
  <p>The above code works as expected. However now, I have data in table which I display by:                 </p>
  
  <pre><code>df = sqlContext.sql("SELECT * FROM people_json")               
  </code></pre>
  
  <p>But if I try to pass a new schema to it by using following command it does not work.                           </p>
  
  <pre><code>df2 = spark.sql("SELECT * FROM people_json", schema=final_struc)
  </code></pre>
  
  <p>It gives the following error:                  </p>
  
  <blockquote>
    <p>sql() got an unexpected keyword argument 'schema'           </p>
  </blockquote>
  
  <p>NOTE: I am using <a href="https://community.cloud.databricks.com/" rel="noreferrer">Databrics Community Edition</a></p>
  
  <ul>
  <li>What am I missing?</li>
  <li>How do I pass the new schema if I have data in the table instead of some JSON file? </li>
  </ul>