apache pig未使用适当的recordwriter或outputcommitter

fkvaft9z  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(159)

问题

我用的是定制的 StoreFunc , OutputFormat ,和 OutputCommitter 用于清管器。我遇到的问题是pig没有调用我在 OutputFormat 返回适当的 RecordWriter 以及 OutputCommitter . 这会导致数据被写到其他地方(我真的不确定在哪里),而不是预期的目的地。Pig在工作中不会犯任何错误。
一个简单的pig脚本示例:

data = LOAD '<url>' USING com.company.CompanyLoader();
STORE data INTO '<other url>' USING com.company.CompanyStorage();

我知道的是:
Pig叫Pig getOutputFormat 上的方法 StoreFunc . 所以这很好。
Pig叫声 checkOutputSpecsOutputFormat . 伟大的。
Pig不叫 getOutputCommitter 也不是 getRecordWriter 在outputformat上。我正在记录pig当前在中使用的outputformat和outputcommitter类型 checkOutputSpecs 方法,结果是 org.apache.hadoop.mapreduce.lib.output.TextOutputFormat 以及 org.apache.hadoop.mapred.DirectFileOutputCommitter . 我不确定这是否意味着pig真的使用了这两种方法中的任何一种,因为我认为pig可以用我自己的方法来代替它们 OutputFormat 以及 OutputCommitter 在调用我的 StoreFunc / OutputCommitter .
我没有明确设定 OutputFormat 也不是 OutputCommitter 在Pig的任何地方。我怀疑那只Pig正在吃别的东西 OutputFormat /其他地方的课程,但我不知道去哪里查。
在这个问题上,有人能提供一些见解或进一步的调试步骤吗?

示例代码

这不是我的实际代码,但它演示了我是如何设置的。我不会在运行时修改配置。
mystorefunc.java文件

public class MyStoreFunc extends StoreFunc {

    CustomOutputFormat OutputFormat = new CustomOutputFormat();
    private RecordWriter out;

    public OutputFormat getOutputFormat() throws IOException {
        LOG.info("getOutputFormat called.");
        return outputFormat;
    }

    public void prepareToWrite(final RecordWriter writer) throws IOException {
        out = writer;
        LOG.info("Using RecordWriter: " + writer.getClass());

        // other preparation
    }

    public void setStoreLocation(final String location, final Job job) {
        try {
            LOG.info("Output format class is set to: " + job.getOutputFormatClass());
        } catch (ClassNotFoundException e) {
            LOG.info("Output foramt class is undefined.");
        }
        LOG.info("Output committer is " + job.getConfiguration().get("mapred.output.committer.class", "undefined"));
        // other preparation
    }

    // other stuff...
}

customoutputformat.java文件

public class CustomOutputFormat<K, V> extends OutputFormat<K, V> {

    public CustomOutputFormat() {
        LOG.info("CustomOutputFormat created.");
    }

    public void checkOutputSpecs(final JobContext context) throws IOException {
        LOG.info("checkOutputSpecs called.");
        try {
            LOG.info("output format = " + context.getOutputFormatClass());
        } catch (ClassNotFoundException e) {
            LOG.info("output format not found.");
        }
        // Check some stuff in configuration
    }

    public OutputCommitter getOutputCommitter(final TaskAttemptContext ctx) {
        LOG.info("getOutputCommitter called.");
        return new CustomOutputCommitter();
    }

    public RecordWriter<K, V> getRecordWriter(final TaskAttemptContext ctx) {
        LOG.info("getRecordWriter called.");
        return new CustomRecordWriter<K, V>();
    }

}

示例日志

来自自定义类的日志输出如下所示:

2015-06-30 00:08:32,100 [main] INFO    CustomOutputFormat created.
2015-06-30 00:08:32,104 [main] INFO    Output format class is set to: class org.apache.hadoop.mapreduce.lib.output.TextOutputFormat
2015-06-30 00:08:32,110 [main] INFO    Output committer is org.apache.hadoop.mapred.DirectFileOutputCommitter
2015-06-30 00:08:32,120 [main] INFO    getOutputFormat called.
2015-06-30 00:08:32,124 [main] INFO    checkOutputSpecs called.
2015-06-30 00:08:32,135 [main] INFO    output format=class org.apache.hadoop.mapreduce.lib.output.TextOutputFormat
2015-06-30 00:08:32,140 [main] INFO    Output format class is set to: class org.apache.hadoop.mapreduce.lib.output.TextOutputFormat
2015-06-30 00:08:32,152 [main] INFO    Output committer is org.apache.hadoop.mapred.DirectFileOutputCommitter
2015-06-30 00:08:32,154 [JobControl] INFO    CustomOutputFormat created.
2015-06-30 00:08:32,156 [JobControl] INFO    Output format class is set to: class org.apache.hadoop.mapreduce.lib.output.TextOutputFormat
2015-06-30 00:08:32,159 [JobControl] INFO    Output committer is org.apache.hadoop.mapred.DirectFileOutputCommitter
2015-06-30 00:08:32,166 [JobControl] INFO    getOutputFormat called.
2015-06-30 00:08:32,169 [JobControl] INFO    checkOutputSpecs called.
2015-06-30 00:08:32,175 [JobControl] INFO    output format=class org.apache.hadoop.mapreduce.lib.output.TextOutputFormat

我注意到的事情: getOutputFormat 以及 getRecordWriter 从来没有被召唤过 CustomOutputFormat . 为什么? prepareToWrite 从不在mystorefunc上调用。什么? checkOutputSpecs 正在调用 CustomOutputFormat ,所以很明显,Pig“知道”这个类,并得到它从 MyStoreFunc .
先谢谢你。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题