在 PySpark 中读取 Lzo 文件

2024-04-02

我是 Spark 新手。我的文件夹中有一堆 LZO 索引文件。索引已完成,如上所示https://github.com/twitter/hadoop-lzo https://github.com/twitter/hadoop-lzo.

文件如下:

1.lzo
1.lzo.index
2.lzo
2.lzo.index

and so on

我想阅读这些文件。我正在使用 newAPIHadoopFile()。

正如所给出的,https://github.com/twitter/hadoop-lzo https://github.com/twitter/hadoop-lzo

我做了以下事情:

val files = sc.newAPIHadoopFile(path, classOf[com.hadoop.mapreduce.LzoTextInputFormat],classOf[org.apache.hadoop.io.LongWritable],classOf[org.apache.hadoop.io.Text])
val lzoRDD = files.map(_._2.toString)

它在 Scala(spark-shell)中运行良好。

但是,我想使用 pyspark (python-spark 应用程序)。我正在做以下事情:

files = sc.newAPIHadoopFile(path,"com.hadoop.mapreduce.LzoTextInputFormat","org.apache.hadoop.io.LongWritable","org.apache.hadoop.io.Text")
lzoRDD = files.map(_._2.toString)

我收到以下错误: AttributeError: 'RDD' 对象没有属性 '_2'

整个代码如下:

import sys
from pyspark import SparkContext,SparkConf

if __name__ == "__main__":
    #Create the SparkContext
     conf = (SparkConf().setMaster("local[2]").setAppName("abc").set("spark.executor.memory", "10g").set("spark.cores.max",10))

     sc = SparkContext(conf=conf)

     path='/x/y/z/*.lzo'
     files = sc.newAPIHadoopFile(path,"com.hadoop.mapreduce.LzoTextInputFormat","org.apache.hadoop.io.LongWritable","org.apache.hadoop.io.Text")
     lzoRDD = files.map(_._2.toString)

     #stop the SparkContext
     sc.stop()

我正在使用spark-submit 提交。

任何帮助,将不胜感激。

谢谢


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 PySpark 中读取 Lzo 文件 的相关文章

随机推荐