在java中运行pig而不嵌入pig脚本 [英] Run pig in java without embedding pig script

查看:36
本文介绍了在java中运行pig而不嵌入pig脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Pig 脚本、Hadoop、Hbase 的新手.这是我需要知道的.我想运行一个 pig 脚本,我不想将 pig 脚本嵌入到我的 java 程序中,而是想通过传递必要的 pig 脚本和参数(可能是参数文件)的任何 Pig Execution 方法来运行它.核心 pig 库或任何其他库是否提供了执行 pig 脚本的方式.我已经尝试过使用 java 运行时 exec 方法,我传递了一些带有空格分隔字符串的参数,所以我放弃了通过运行时 exec 方法调用 pig grunt 命令,因为它不是执行 pig 命令的正确方法.

I am new to pig script, Hadoop, Hbase. Here's what i need to know. I wanted to run a pig script, I don't want to embed the pig script in my java program and wanted to run it through any Pig Execution methods passing the necessary pig script and parameters (possibly parameter file). Does the core pig library or any other library provides that way to execute a pig script. I already tried with java run-time exec method, I pass some parameters with space separated strings so i dropped calling pig grunt command through run-time exec method since it is not the proper way to execute pig commands.

推荐答案

您可以使用 org.apache.pig.PigServer 从 Java 程序运行 pig 脚本.

You can use org.apache.pig.PigServer to run pig scripts from Java programs.

PigServer pigServer = new PigServer(ExecType.MAPREDUCE);
pigServer.registerScript("scripts/test.pig");

在类路径上需要pig.properties".

Requires 'pig.properties' on classpath.

fs.default.name=hdfs://<namenode-hostname>:<port>
mapred.job.tracker=<jobtracker-hostname>:<port>

或者将 java.util.Properties 的一个实例传递给 PigServer 构造函数.

Or pass an instance of java.util.Properties to PigServer constructor.

Properties props = new Properties();
props.setProperty("fs.default.name", "hdfs://<namenode-hostname>:<port>");
props.setProperty("mapred.job.tracker", "<jobtracker-hostname>:<port>");
PigServer pigServer = new PigServer(ExecType.MAPREDUCE, props);

这篇关于在java中运行pig而不嵌入pig脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆