PySpark將dataframe寫入本地文件,只生成文件夾含有SUCCESS

  1. 代碼
results = res.rdd\
          .map(lambda word: (word[0].replace(u"(", u"(").replace(u")", u")"), word[1], word[2]))\
          .filter(lambda word: word[0] in companys_list)\
          .map(lambda word: (companys_dic.get(word[0], word[0]),word[1], word[2]))\
          .filter(lambda word: word[1] != None and word[1] != u'None')
 
schemaString = "company_name,query,keyword"
fields = list(map(lambda fieldName : StructField(fieldName, StringType(), nullable = True), schemaString.split(",")))
schema = StructType(fields)
results_df = self.spark.createDataFrame(results, schema).distinct()
 
#results_df.show(100)
output_file = "file:///home/spark/query_20200520_uniq.csv"
results_df.write.mode("overwrite").options(header="true").csv(output_file, sep='\t')

但是運(yùn)行結(jié)束只得到一個(gè)文件夾,并沒有得到期望的結(jié)果,查閱資料發(fā)現(xiàn)保存到本地文件系統(tǒng)(file:///)只有再local模式下才能生效,在cluster模式下(不論是yarn-client還是yarn-cluster)都無法使用。

因此需要修改運(yùn)行腳本,設(shè)置--master local[*] 。最終得到了期望的數(shù)據(jù)。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、Spark運(yùn)行模式 1.1 local 本地模式:常用于本地開發(fā)測(cè)試 例如,程序中或-Master中傳參數(shù)lo...
    吾系司機(jī)閱讀 867評(píng)論 0 0
  • Zookeeper用于集群主備切換。 YARN讓集群具備更好的擴(kuò)展性。 Spark沒有存儲(chǔ)能力。 Spark的Ma...
    Yobhel閱讀 7,602評(píng)論 0 34
  • 下載 Spark 1.官網(wǎng)地址http://spark.apache.org/ 2.文檔查看地址https://s...
    shawn_3381閱讀 398評(píng)論 0 0
  • 17.分區(qū)分桶的區(qū)別,為什么要分區(qū) 分區(qū)表:原來的一個(gè)大表存儲(chǔ)的時(shí)候分成不同的數(shù)據(jù)目錄進(jìn)行存儲(chǔ)。如果說是單分區(qū)表,...
    qydong閱讀 766評(píng)論 0 0
  • 1、 性能調(diào)優(yōu) 1.1、 分配更多資源 1.1.1、分配哪些資源? Executor的數(shù)量 每個(gè)Executor所...
    Frank_8942閱讀 4,840評(píng)論 2 36

友情鏈接更多精彩內(nèi)容