Spark is designed to write out multiple files in parallel. So there may be cases where we need to merge all the part files, remove the success/commit files and write the content to a single file.
This blog helps you to write spark output to a single file.
Using df.coalesce(1) we can write data to a single file,
result_location = "dbfs:///mnt/datalake/unmesha/output/" df.coalesce(1).write.format("csv").options(header='true').mode("overwrite").save(result_location)
but still you will see _success files.
This solution - adding coalesce isn’t sufficient when you want to write data to a file with a specific name.
We are going to achieve this using dbutils
result_location = "dbfs:///mnt/datalake/unmesha/output/"
df.coalesce(1).write.format("csv").options(header='true').mode("overwrite").save(result_location)
files = dbutils.fs.ls(result_location)
csv_file = [x.path for x in files if x.path.endswith(".csv")][0]
dbutils.fs.mv(csv_file, result_location.rstrip('/') + ".csv")
dbutils.fs.rm(result_location, recurse = True)
Above snippet helps you to write dataframe output to a single file with a specific name.
Live Seacoin Price from all markets and SEA coin market Capitalization. Stay up to date with the latest SEA price movements and forum discussion. Check out our snapshot charts and see when there is an opportunity to buy or sell.
ReplyDeleteFast-track your data analytics and machine learning course with guaranteed placement opportunities. Most extensive, industry-approved experiential learning program ideal for future Data Scientists.
ReplyDeleteblog is nice and much interesting which engaged me more.Spend a worthful time.keep updating more.
ReplyDeleteibm full form in india |
ssb ka full form |
what is the full form of dp |
full form of brics |
gnm nursing full form |
full form of bce |
full form of php |
bhim full form |
nota full form in india |
apec full form |
Great article. Your blogs are unique and simple that is understood by anyone.
ReplyDeleteBCom First Year Time Table PDF
Get one of the best import export data provider for Mexico Import and Export Data. For more information visit our website and complete details about our import export data services.
ReplyDeleteMexico Import Data
Thanks for sharing this blog.
ReplyDeleteDiscover exquisite resorts for team outings in Ooty. Tailored amenities, stunning locales, and a perfect blend of relaxation and team-building activities.