我试图找到在java中对整个pig脚本运行explain命令的方法。 我使用的是PigServer,但它只提供单个查询(别名)而不是整个脚本的解释。 有没有办法做类似的事情:
$ pig -x local -e 'explain -script Temp1/TPC_test.pig -out explain-out9.txt'
但是来自我的Java代码?
答案 0 :(得分:5)
您可以将PigRunner用于此目的 E.g:
import org.apache.pig.PigRunner;
import org.apache.pig.tools.pigstats.PigStats;
public class PigTest {
public static void main(String[] args) throws Exception {
args = new String [] {
"-x", "local",
"-e", "explain -script Temp1/TPC_test.pig -out explain-out9.txt"
};
PigStats stats = PigRunner.run(args, null);
//print plan:
//stats.getJobGraph().explain(System.out, "text", true);
}
}
我发现需要以下运行时依赖项来避免 NoClassDefFoundError :
答案 1 :(得分:0)
您可以使用org.apache.pig.PigServer从Java程序运行pig脚本:
PigServer pigServer = new PigServer(ExecType.MAPREDUCE);
pigServer.registerScript("scripts/test.pig");
Requires 'pig.properties' on classpath.
fs.default.name=hdfs://<namenode-hostname>:<port>
mapred.job.tracker=<jobtracker-hostname>:<port>
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);
希望这有帮助
答案 2 :(得分:0)
当然你也可以使用grunt shell! (我总是忘记这一点。)
在我们的网站上,我们使用了一个启动器脚本来编写如下的猪调用命令:
$ pig -p param1=foo -p param2=bar script.pig
您可以在grunt shell中使用explain -script
:
pig
explain
看起来像:
$ pig
grunt> explain -param param1=foo -param param2=bar script.pig