关于java:Java-mapreduce解析parquet日志

3次阅读

共计 1286 个字符,预计需要花费 4 分钟才能阅读完成。

1. 单输出格局

指定输出格局 ParquetInputFormat

// 指定输出格局
job.setInputFormatClass(ParquetInputFormat.class);
ParquetInputFormat.addInputPath(job, new Path(args[1]));
ParquetInputFormat.setReadSupportClass(job, CheckLevelRunner.MyReadSupport.class);

// 这个提供的是定义读文件的形式
public static final class MyReadSupport extends DelegatingReadSupport<Group> {public MyReadSupport() {super(new GroupReadSupport());
    }

    @Override
    public org.apache.parquet.hadoop.api.ReadSupport.ReadContext init(InitContext context) {return super.init(context);
    }
}

解析 Parquet 遇到空文件的状况:

此时能够设置 mapreduce 容错参数:
Mapreduce.map.failures.maxpercent:这个参数示意当 Map Task 失败比例超过该值,则整个作业失败,默认值为 0。在这里设置成 5,在这里 map 的数量与输出文件数量统一,因而如果空文件的数量小于 5%,则工作会胜利,大于 5%,工作失败。

job.getConfiguration().set("mapreduce.map.failures.maxpercent", "5");

2. 多输出格局

其中一个目录的文件格式是 Text,另一个是 Parquet。应用 MultipleInputs 依据输出源设置多个 map 来解决数据。

// 设置多输出、多 mapper
MultipleInputs.addInputPath(job, new Path(path1), TextInputFormat.class, NormalMap.class);
MultipleInputs.addInputPath(job, new Path(path2), ParquetInputFormat.class, ParquetMap.class);
ParquetInputFormat.setReadSupportClass(job, CheckLevelRunner.MyReadSupport.class);

3.mapreduce 中调用 http 接口遇到的问题

将程序部署服务器上,发现会报这个错:
Exception in thread “main” java.lang.NoSuchFieldError: INSTANCE,
考察发现,是因为 httpclient 有两个版本,本人引入了 4 的版本,而 org.apache.hadoop 这个包中蕴含了 httpclient3.1 的版本,两个版本抵触,最初去掉了本人引入的版本,应用了 hadoop 包中 3.1 的 httpclient。

正文完
 0