apache-spark - 如何将二进制文件传输到spark中的rdd中?

标签 apache-spark rdd

我正在尝试将seg-Y类型文件加载到spark中,并将它们传输到rdd中进行mapreduce操作。 但我未能将它们转入rdd。有谁可以提供帮助吗?

最佳答案

您可以使用 binaryRecords() pySpark 调用将二进制文件的内容转换为 RDD

http://spark.apache.org/docs/latest/api/python/pyspark.html#pyspark.SparkContext.binaryRecords

binaryRecords(path, recordLength)

Load data from a flat binary file, assuming each record is a set of numbers with the specified numerical format (see ByteBuffer), and the number of bytes per record is constant.

Parameters: path – Directory to the input data files recordLength – The length at which to split the records

然后您可以使用 struct.unpack() 等方法将该 RDD 映射() 到结构中

https://docs.python.org/2/library/struct.html

我们使用这种方法来获取固定宽度记录二进制文件。有一些 Python 代码可以生成格式字符串(struct.unpack 的第一个参数),但如果您的文件布局是静态的,则手动执行一次相当简单。

使用纯 Scala 也可以实现类似的效果:

http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.SparkContext@binaryRecords(path:String,recordLength:Int,conf:org.apache.hadoop.conf.Configuration):org.apache.spark.rdd.RDD[Array[Byte]]

关于apache-spark - 如何将二进制文件传输到spark中的rdd中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32602489/

相关文章:

json - 在读取 json 时解释 Spark 中的时间戳字段

python - 如何将python函数编写为返回字典类型的udf

scala - uber jar 中的 NoSuchMethodError 异常

python - 从 SPARK 中的另一个 RDD 返回最大 N 值的 RDD

apache-spark - 如何将行rdd转换为类型化rdd

返回多个 RDD 的 Java Spark 映射步骤

scala - 如何避免在 Scala 的 Spark RDD 中使用收集?

apache-spark - Spark Master 填充临时目录

python - pyspark 抛出 TypeError : textFile() missing 1 required positional argument: 'name'

java - 在Spark Java API中联接行数据集