簡體   English   中英

根據Spark中的空行拆分文本文件

[英]Splitting a text file based on empty lines in Spark

我正在處理一個非常大的文件,它是一個幾乎 2GB 的非常大的文本文檔。

像這樣的東西 -

\#\*MOSFET table look-up models for circuit simulation
\#t1984
\#cIntegration, the VLSI Journal
\#index1

\#\*The verification of the protection mechanisms of high-level language machines
\#@Virgil D. Gligor
\#t1984
\#cInternational Journal of Parallel Programming
\#index2

\#\*Another view of functional and multivalued dependencies in the relational database model
\#@M. Gyssens, J. Paredaens
\#t1984
\#cInternational Journal of Parallel Programming
\#index3

\#\*Entity-relationship diagrams which are in BCNF
\#@Sushil Jajodia, Peter A. Ng, Frederick N. Springsteel
\#t1984
\#cInternational Journal of Parallel Programming
\#index4

我想在 spark 中讀取它們並根據 spark 中的空塊拆分它們並在 PySpark 中創建這些數據的塊。

#*Entity-relationship diagrams which are in BCNF #@Sushil Jajodia, Peter A. Ng, Frederick N. Springsteel #t1984 #cInternational Journal of Parallel Programming #index4

我目前寫的代碼是rdd = sc.textFile('acm.txt').flatMap( lambda x: x.split("\n\n") )

據我了解,您想在 spark 中讀取此文本文件,並且每段有一條記錄。 為此,您可以像這樣更改記錄分隔符(默認情況下為\n ):

在 scala 中:

sc.hadoopConfiguration.set("textinputformat.record.delimiter","\n\n")
val rdd = sc.textFile("acm.txt")

在 python 中(您需要訪問 java spark 上下文才能訪問 hadoop 配置):

sc._jsc.hadoopConfiguration().set("textinputformat.record.delimiter","\n\n")
rdd = sc.textFile("acm.txt")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM