<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: How to save all the output of pyspark sql query into a text file or any file in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/298047#M218961</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/78996"&gt;@shubh&lt;/a&gt;&amp;nbsp;As this is an older post that has been marked solved in 2018. You would have a better chance of receiving a resolution by &lt;A href="https://community.cloudera.com/t5/forums/postpage/board-id/Questions" target="_self"&gt;starting a new thread&lt;/A&gt;. This will also provide the opportunity to provide details specific to your environment that could aid others in providing a more accurate answer to your question.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jun 2020 07:07:10 GMT</pubDate>
    <dc:creator>VidyaSargur</dc:creator>
    <dc:date>2020-06-15T07:07:10Z</dc:date>
    <item>
      <title>How to save all the output of pyspark sql query into a text file or any file</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204560#M166549</link>
      <description>&lt;P&gt;Hello community,&lt;/P&gt;&lt;P&gt;The output from the pyspark query below produces the following output&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="83554-spark.png" style="width: 404px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/17167i40D98B30EB5E3F51/image-size/medium?v=v2&amp;amp;px=400" role="button" title="83554-spark.png" alt="83554-spark.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The pyspark query is as follows:&lt;/P&gt;&lt;PRE&gt;#%%
import findspark
findspark.init('/home/packt/spark-2.1.0-bin-hadoop2.7')
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName('ops').getOrCreate()
df = spark.read.csv('/home/packt/Downloads/Spark_DataFrames/HumanResources_vEmployeeDepartment.csv',inferSchema=True,header=True)
df.createOrReplaceTempView('HumanResources_vEmployeeDepartment')
myresults = spark.sql("""SELECT
  FirstName
 ,LastName
 ,JobTitle
FROM HumanResources_vEmployeeDepartment
ORDER BY FirstName, LastName DESC""")
myresults.show()&lt;/PRE&gt;&lt;P&gt;Can someone show me how to save the results to a text / csv file ( or any file please)&lt;/P&gt;&lt;P&gt;Thanks Carlton&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 13:33:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204560#M166549</guid>
      <dc:creator>barlow</dc:creator>
      <dc:date>2022-09-16T13:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to save all the output of pyspark sql query into a text file or any file</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204561#M166550</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/63166/carlton.html" nodeid="63166"&gt;@Carlton Patterson&lt;/A&gt; &lt;/P&gt;&lt;P&gt;You can use this to write whole dataframe to single file:&lt;/P&gt;&lt;PRE&gt;myresults.coalesce(1).write.csv("/tmp/myresults.csv")&lt;/PRE&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 20:21:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204561#M166550</guid>
      <dc:creator>falbani</dc:creator>
      <dc:date>2018-08-06T20:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to save all the output of pyspark sql query into a text file or any file</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204562#M166551</link>
      <description>&lt;P&gt;Felix, thank you so much. It worked like a dream&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 03:56:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204562#M166551</guid>
      <dc:creator>barlow</dc:creator>
      <dc:date>2018-08-07T03:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to save all the output of pyspark sql query into a text file or any file</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204563#M166552</link>
      <description>&lt;P&gt;Is there a way to get the results with the header info?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 04:02:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204563#M166552</guid>
      <dc:creator>barlow</dc:creator>
      <dc:date>2018-08-07T04:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to save all the output of pyspark sql query into a text file or any file</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204564#M166553</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/63166/carlton.html" nodeid="63166"&gt;@Carlton Patterson&lt;/A&gt; &lt;/P&gt;&lt;PRE&gt;myresults.coalesce(1).write.format('csv').save("/tmp/myresults.csv", header='true')&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Oct 2018 18:40:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/204564#M166553</guid>
      <dc:creator>mark_hadoop</dc:creator>
      <dc:date>2018-10-02T18:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to save all the output of pyspark sql query into a text file or any file</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/297998#M218929</link>
      <description>&lt;P&gt;Getting permission denied error :Permission denied: user=cldraproc, access=WRITE, inode="/":yarn:supergroup:drwxr-xr-x&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;df.coalesce(1).write.format('csv').save("/home/cldraproc/shobhit/ccorp.csv", header='true');&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jun 2020 05:24:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/297998#M218929</guid>
      <dc:creator>shubh</dc:creator>
      <dc:date>2020-06-13T05:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to save all the output of pyspark sql query into a text file or any file</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/298047#M218961</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/78996"&gt;@shubh&lt;/a&gt;&amp;nbsp;As this is an older post that has been marked solved in 2018. You would have a better chance of receiving a resolution by &lt;A href="https://community.cloudera.com/t5/forums/postpage/board-id/Questions" target="_self"&gt;starting a new thread&lt;/A&gt;. This will also provide the opportunity to provide details specific to your environment that could aid others in providing a more accurate answer to your question.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 07:07:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-save-all-the-output-of-pyspark-sql-query-into-a-text/m-p/298047#M218961</guid>
      <dc:creator>VidyaSargur</dc:creator>
      <dc:date>2020-06-15T07:07:10Z</dc:date>
    </item>
  </channel>
</rss>

