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