本帖最后由 tianhailong 于 2018-03-14 21:01 編輯
我目前做一個(gè)spark 應(yīng)用開發(fā), 讀取一些點(diǎn)云數(shù)據(jù)(二進(jìn)制格式),隨后做一系列處理后 保存為普通的二進(jìn)制文件,保存在 hdfs上邊,
我使用python 開發(fā),通過hadoop 文件api 寫文件到hdfs Path = sc._gateway.jvm.org.apache.hadoop.fs.Path
FileSystem = sc._gateway.jvm.org.apache.hadoop.fs.FileSystem
Configuration = sc._gateway.jvm.org.apache.hadoop.conf.Configuration
def save_file_content(fileContent, fileName, savePath, Path, FileSystem, Configuration):
fs = FileSystem.get(Configuration())
output = fs.create(Path(savePath + "/" + fileName))
output.write(bytearray(fileContent))
output.close()
但是這個(gè)只能在driver 機(jī)器執(zhí)行,我把rdd 放在 driver 機(jī)器遍歷寫入, content = rdd.collect() for i in content: save(i, savePath, Path, FileSystem, Configuration)
但是這種方式數(shù)據(jù)量大時(shí)會(huì)內(nèi)存溢出,請(qǐng)問有什么更好的方向?qū)懭雋dfs 嗎?
|