【问题标题】:How to omit empty part-000x files from Python streaming MapReduce job如何从 Python 流式 MapReduce 作业中省略空的 part-000x 文件
【发布时间】:2015-05-04 12:07:25
【问题描述】:

我创建了一个 Python 映射器,我将其作为 Hadoop 流式 MapReduce 作业运行。它验证输入并在输入无效时将消息写入输出。

...
# input from STDIN
for line in sys.stdin:
    indata = json.loads(line)
    try:
        jsonschema.validate(indata,schema)
    except jsonschema.ValidationError, error:
        # validation against schema failed
        print error.message
    except:
        # other exceptions
        raise

我的问题:映射器按预期写入无效输入的消息,但它也为有效输入创建空的“part-0000x”文件。

我想省略空输出文件。我怎样才能做到这一点?

【问题讨论】:

    标签: python hadoop mapreduce hadoop-streaming


    【解决方案1】:

    要省略空输出文件,请使用LazyOutputFormatclass。仅当为特定文件生成至少一条记录时,它才会生成部分文件。

    但是LazyOutputFormat在Java API中,你可以找到对应的Python API

    【讨论】:

    • 谢谢你这是正确的。由于我使用 Hadoop Streaming,我可以将参数“-lazyOutput”传递给 Streaming 作业,尽管逻辑使用 Python。
    猜你喜欢
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-20
    相关资源
    最近更新 更多