title: How to export data from Spark SQL to CSV
body: <p>This command works with HiveQL:</p>
  
  <pre><code>insert overwrite directory '/data/home.csv' select * from testtable;
  </code></pre>
  
  <p>But with Spark SQL I'm getting an error with an <code>org.apache.spark.sql.hive.HiveQl</code> stack trace:</p>
  
  <pre><code>java.lang.RuntimeException: Unsupported language features in query:
      insert overwrite directory '/data/home.csv' select * from testtable
  </code></pre>
  
  <p>Please guide me to write export to CSV feature in Spark SQL.</p>