【问题标题】:PySpark read in a big customized line ending filePySpark 读入一个大的自定义行尾文件
【发布时间】:2018-02-14 02:48:38
【问题描述】:

文件大小为 20 GB,行尾字符为 ␀。以下是 PySpark 代码:

text_file = sc.textFile(file_name)
counts = text_file.flatMap(lambda line: line.split("␀"))
counts.count()

错误如下: 换行符前的字节过多:2147483648

问题:如何使用 PySpark 读取大型自定义行尾文件?

【问题讨论】:

    标签: apache-spark pyspark apache-spark-sql line-endings


    【解决方案1】:

    您可以使用与creating spark data structure from multiline record中相同的技术

    rdd = sc.newAPIHadoopFile(
        '/tmp/weird',
        'org.apache.hadoop.mapreduce.lib.input.TextInputFormat',
        'org.apache.hadoop.io.LongWritable',
        'org.apache.hadoop.io.Text',
        conf={'textinputformat.record.delimiter': '␀'}
    ).values()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-10
      • 2011-11-04
      • 2019-02-10
      • 1970-01-01
      • 2017-12-16
      相关资源
      最近更新 更多