pigserver java,在Java中执行PigServer时出错

I am trying to run pig scripts remotely from my java machine, for that i have written below code

code:

import java.io.IOException;

import java.util.Properties;

import org.apache.pig.ExecType;

import org.apache.pig.PigServer;

import org.apache.pig.backend.executionengine.ExecException;

public class Javapig{

public static void main(String[] args) {

try {

Properties props = new Properties();

props.setProperty("fs.default.name", "hdfs://hdfs://192.168.x.xxx:8022");

props.setProperty("mapred.job.tracker", "192.168.x.xxx:8021");

PigServer pigServer = new PigServer(ExecType.MAPREDUCE, props);

runIdQuery(pigServer, "fact");

}

catch(Exception e) {

System.out.println(e);

}

}

public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {

pigServer.registerQuery("A = load '" + inputFile + "' using org.apache.hive.hcatalog.pig.HCatLoader();");

pigServer.registerQuery("B = FILTER A by category == 'Aller';");

pigServer.registerQuery("DUMP B;");

System.out.println("Done");

}

}

but while executing i am getting below error.

Error

ERROR 4010: Cannot find hadoop configurations in classpath (neither hadoop-site.xml nor core-site.xml was found in the classpath).

I don't know what am i doing wrong.

解决方案

Well, self describing error...

neither hadoop-site.xml nor core-site.xml was found in the classpath

You need both of those files in the classpath of your application.

You ideally would get those from your $HADOOP_CONF_DIR folder, and you would copy them into your Java's src/main/resources, assuming you have a Maven structure

Also, with those files, you should rather use a Configuration object for Hadoop

PigServer(ExecType execType, org.apache.hadoop.conf.Configuration conf)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值