【问题标题】:Error executing PigServer in Java在 Java 中执行 PigServer 时出错
【发布时间】:2016-09-19 13:39:30
【问题描述】:

我正在尝试从我的 java 机器远程运行 pig 脚本,因为我已经在下面编写了代码

代码:

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");
 }
}

但是在执行时我遇到了错误。

错误

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

我不知道我做错了什么。

【问题讨论】:

    标签: java hadoop apache-pig bigdata


    【解决方案1】:

    好吧,自我描述错误......

    在类路径中找不到 hadoop-site.xml 和 core-site.xml

    您的应用程序的类路径中需要这两个文件。

    如果你有一个 Maven 结构,最好从 $HADOOP_CONF_DIR 文件夹中获取它们,然后将它们复制到 Java 的 src/main/resources

    此外,对于这些文件,您应该为 Hadoop 使用 Configuration 对象

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-10
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      • 2013-06-12
      相关资源
      最近更新 更多