In python, bytes string can be simply saved to single xml file:
with open('/home/user/file.xml' ,'wb') as f:
f.write(b'<Value>1</Value>')
Current output : /home/user/file.xml (file saved in local file)
Question: How to save string to xml file on hdfs in pyspark:
Expected output: 'hdfs://hostname:9000/file.xml'
Background: Large amount of xml files are provided by 3rd party web APIs. I build ETL pipeline in pyspark to delta lake. Data are extracted asynchronously by aiohttp, next I want to use spark-xml for transformation before saving spark data frame to delta lake(requires pyspark). I'm looking for most efficient way to buid the pipeline.
Similar question was asked spark-xml developers on github. https://github.com/databricks/spark-xml/issues/515
Latest research:
spark-xml use as an input xml files directly stored as text on the disk or spark dataframe
So I'm limited to use one of 2 options below:
a) some hdfs client(pyarrow,hdfs,aiohdfs) to save files to hdfs (text file on hdfs is not very efficient format)
b) load data to spark dataframe for spark-xml transformation(native format for delta lake)
If you have other ideas, please let me know.