java - 在 Java 中执行 PigServer 时出错

标签 java hadoop apache-pig bigdata

我正在尝试从我的 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).

我不知道我做错了什么。

最佳答案

嗯, self 描述错误...

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

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

理想情况下,你会从你的$HADOOP_CONF_DIR 文件夹中获取它们,然后将它们复制到你的 Java 的 src/main/resources 中,假设你有一个 Maven 结构

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

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

关于java - 在 Java 中执行 PigServer 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39574653/

相关文章:

hadoop - Pig 中的 SUM、AVG 不起作用

java - 切片一个非常大的 jpg map 图像,49000* 34300 像素

Java sqlite 行在 Select 查询后消失

hadoop - 将合并器用于mapreduce二级排序

java - 在本地机器上运行 mapreduce 时在 IDEA 和集群上的 hadoop 上运行不同的输出

apache-spark - Spark检查是否存在带有正则表达式的输入路径

hadoop - 使用 Apache PIG 创建空表

java - 有没有一种方法可以通用地测量物体的大小或长度?

java - 正则表达式捕获特殊字符时出错

hadoop - 总结 Pig 中的值