pig脚本问题

tvz2xvvm  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(449)

我正在使用pig with hcatalog从配置单元外部表加载数据我使用pig-usehcatalog输入grunt并执行以下操作:

register 'datafu'

define Enumerate datafu.pig.bags.Enumerate('1');

imported_data  = load 'hive external table' using org.apache.hive.hcatalog.pig.HCatLoader() ;

converted_data = foreach imported_data generate name,ip,domain,ToUnixTime(ToDate(dateandtime,'MM/dd/yyyy hh:mm:ss.SSS aa'))as unix_DateTime,date;

grouped = group converted_data by (name,ip,domain);

result = FOREACH grouped {
             sorted = ORDER converted_data BY unix_DateTime;
             sorted2 = Enumerate(sorted);
             GENERATE FLATTEN(sorted2);
};

所有命令都运行并提供所需的结果。
问题:我用上面名为pigfinal.pig的命令创建了一个pig脚本,并在本地文件系统中以本地模式coz脚本执行了以下命令。

pig -useHCatalog -x local '/path/to/pigFinal.pig';

例外
无法生成逻辑计划。嵌套异常:org.apache.pig.backend.executionengine.executexception:错误1070:无法使用导入解析datafu.pig.bags.enumerate:[,java.lang.,org.apache.pig.builtin。,org.apache.pig.impl.builtin.]位于org.apache.pig.parser.logicalplanbuilder.buildudf(logicalplanbuilder)。java:1507)位于org.apache.pig.parser.logicalplangerator.func\u eval(logicalplangerator。java:9372)位于org.apache.pig.parser.logicalplangerator.projectable\u expr(logicalplangerator。java:11051)在org.apache.pig.parser.logicalplanggenerator.var\u expr(logicalplanggenerator。java:10810)位于org.apache.pig.parser.logicalplangerator.expr(logicalplangerator。java:10159)在org.apache.pig.parser.logicalplangerator.nested\ u命令(logicalplangerator。java:16315)在org.apache.pig.parser.logicalplanggenerator.nested\u blk(logicalplanggenerator。java:16116)在org.apache.pig.parser.logicalplangerator.foreach\u计划(logicalplangerator。java:16024)在org.apache.pig.parser.logicalplangerator.foreach\ u子句(logicalplangerator。java:15849)在org.apache.pig.parser.logicalplangerator.op\子句(logicalplangerator。java:1933)在org.apache.pig.parser.logicalplangerator.general\语句(logicalplangerator。java:1102)位于org.apache.pig.parser.logicalplangerator.statement(logicalplangerator。java:560)在org.apache.pig.parser.logicalplangerator.query(logicalplangerator。java:421)在org.apache.pig.parser.queryparserdriver.parse(queryparserdriver。java:188) ... 还有17个
我需要在哪里为pig脚本注册datafu jar?我想这就是问题所在。请帮忙

xpcnnkqh

xpcnnkqh1#

您必须确保jar文件与pigscript位于同一文件夹中,或者在注册jar文件时确保pigscript中提供了正确的路径。对你来说
修改此

register 'datafu'

-- If,lets say datafu-1.2.0.jar is your jar file and is located in the same folder as your pigscript then in your pigscript at the top have this
REGISTER datafu-1.2.0.jar 

-- Else,lets say datafu-1.2.0.jar is your jar file and is located in the folder /usr/hadoop/lib then in your pigscript at the top have this
REGISTER /usr/hadoop/lib/datafu-1.2.0.jar
igsr9ssn

igsr9ssn2#

pig -useHCatalog \
    -x local \
    -Dpig.additional.jars="/local/path/to/datafu.jar:/local/path//other.jar" \ 
    /path/to/pigFinal.pig;


在pig脚本中使用完全限定路径 register /local/path/to/datafu.jar;

相关问题