How to use .jar in a pig file

安稳与你 提交于 2019-12-24 02:38:05

问题


I have two input files smt.txt and smo.txt. The jar file reads the text files and split the data according to some rule which is described in java file. And the pig file takes these data put into output files with doing mapreduce.

register 'maprfs:///user/username/fl.jar';
DEFINE FixedLoader fl();

mt = load 'maprfs:///user/username/smt.txt' using FixedLoader('-30','30-33',...........) AS (.........);

mo = load 'maprfs:///user/username/smo.txt*' using FixedLoader('-30','30-33',.....) AS (......);

store mt into 'maprfs:///user/username/mt_out' using JsonStorage();
store mo into 'maprfs:///user/username/mo_out' using JsonStorage();

and a part of java code like in the following. (The content of methods are not neccessary I believe):

package com.mapr.util;

import org.apache.hadoop.mapreduce.lib.input.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.io.*;
import org.apache.pig.*;
import org.apache.pig.data.*;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.*;
import java.util.*;
import java.io.*;

public class FixedLoader extends LoadFunc
{

............

}

When I run this pig program in a teminal with the command "pig -x mapreduce sample.pig", I gave an Error message:

ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve com.mapr.util.FixedLoader using imports: [, org.apache.pig.builtin., org.apache.pig.impl.builtin.]

How can I import these into my project or are there any suggestions/solutions to run this program?


回答1:


You need to define FixedLoader with its full package name:

register 'maprfs:///user/username/fl.jar';
DEFINE FixedLoader com.mapr.util.FixedLoader();
...

Also register all of the 3rd party dependency jars that are used in your custom UDF.



来源:https://stackoverflow.com/questions/13789121/how-to-use-jar-in-a-pig-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!