Save pyspark dataframe entires as separate html files on s3

Viewed 17

So, if I have a list of file locations on s3, I can build a dataframe with a column containing the contents of each file in a separate row by doing the following (for example):

s3_path_list = list(df.select('path').toPandas()['path']))

df2 = spark.read.format("binaryFile").load(s3_path_list,'path')

which returns:

df2: pyspark.sql.dataframe.DataFrame
path:string
modificationTime:timestamp
length:long
content:binary

What is the inverse of this operation?

Specifically... I have plotly generating html content stored as a string in an additional 'plot_string' column.

df3: pyspark.sql.dataframe.DataFrame
save_path:string
plot_string:string

How would I go about efficiently saving off each 'plot_string' entry as an html file at some s3 location specified in the 'save_path' column?

Clearly some form of df.write can be used to save off the dataframe (bucketed or partitioned) as parquet, csv, text table, etc... but I can't seem to find any straightforward method to perform a simple parallel write operation without a udf that initializes separate boto clients for each file... which, for large datasets, is a bottleneck (as well as being inelegant). Any help is appreciated.

0 Answers
Related