山东大学软件工程应用与实践——Pig代码分析(九)

2021SC@SDUSC

概述
本次继续分析pig作为hadoop的轻量级脚本语言操作hadoop的executionengine包下的MapReduceLayer类的代码

此类用于让 POStore 通过输出收集器/记录编写器写入 DFS。它设置修改后的作业配置,以强制写入主输出目录的特定子目录。这样做是为了能在同一作业中使用多个输出目录。

MapReducePOStoreImpl方法
获取配置的副本,以便对以下配置的更改(如设置输出位置)不会影响调用方的副本
制作一个上下文的副本以在此处使用 - 因为在同一任务(映射或减少)中,我们可以有多个存储,我们应该制作此副本,以便相同的上下文不会被不同的存储覆盖。

public MapReducePOStoreImpl(TaskInputOutputContext<?,?,?,?> context) {
        Configuration outputConf = new Configuration(context.getConfiguration());
        reporter = PigStatusReporter.getInstance();
        reporter.setContext(new MRTaskContext(context));
        this.context = HadoopShims.createTaskAttemptContext(outputConf,
                context.getTaskAttemptID());
    }

StoreFuncInterface接口
在 storeFunc 上调用 setStoreLocation,为其提供 Job。这将导致
storeFunc 将输出位置存储在作业的配置中。PigOutFormat.setLocation方法会将此修改后的配置合并到我们拥有的上下文的配置中。

public StoreFuncInterface createStoreFunc(POStore store)
            throws IOException {

        StoreFuncInterface storeFunc = store.getStoreFunc();

        PigOutputFormat.setLocation(context, store);
        OutputFormat<?,?> outputFormat = storeFunc.getOutputFormat();
        try {
            writer = outputFormat.getRecordWriter(context);
        } catch (InterruptedException e) {
            throw new IOException(e);
        }

        storeFunc.prepareToWrite(writer);

        return storeFunc;
    }

其中
try {
writer = outputFormat.getRecordWriter(context);
} catch (InterruptedException e) {
throw new IOException(e);
}
用来创建新的记录编写器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值