如何防止将空的Avro文件提交到HDFS? [英] How to prevent committing of an empty Avro file into HDFS?

查看:215
本文介绍了如何防止将空的Avro文件提交到HDFS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一份工作可以将Avro文件创建到HDFS中,并将文件附加到数据中。然而,偶尔不会有任何数据需要追加,在这种情况下,我不希望应用程序刷新和关闭文件,而是应该检查文件是否为空(但我假设Avro模式将被写入这个头文件在技术上并不是一个空文件),如果它是空的,就删除它。



这对于Avro + HDFS lib是否可行? 使用 org / apache / hadoop / mapreduce / lib / output / LazyOutputFormat.htmlrel =nofollow> LazyOutputFormat 指定作业的输出格式。它会懒散地创建输出,这意味着只有输出存在时才会创建输出文件。

因此,不要写如下所示的内容:
job.setOutputFormatClass(TextOutputFormat.class);

您可以像这样使用LazyOutputFormat:
LazyOutputFormat.setOutputFormatClass(job,TextOutputFormat.class);

I have a job that create a Avro file into HDFS and append the file with data. However, occasionally there wont be any data for appending, in that case I don't want the application to flush and close the file, instead it should check whether the file is empty or not (but I assume thatthe Avro schema will be written into the header so technically not an empty file) and delete the file if it is empty.

Is this feasible with Avro+HDFS lib?

解决方案

Try using LazyOutputFormat when specifying the output format for your job. It creates output lazily, meaning that an output file will only be created if output exists.

So instead of writing something like: job.setOutputFormatClass(TextOutputFormat.class);

You can use LazyOutputFormat like this instead: LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class);

这篇关于如何防止将空的Avro文件提交到HDFS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆