使用HDInsight将参数传递给Pig脚本

时间:2013-04-23 12:41:02

标签: apache-pig hdinsight

我在Windows上使用HDInsight安装Hadoop,并尝试将参数传递给pig脚本。我在不同的机器上使用了几个脚本,所以我认为它可能是Windows的东西。我已经输入默认值来检查脚本中的参数工作

示例脚本:

%default myParam 'foo'
load('$myParam');

从命令行以干运行方式运行以进行测试: pig -r testSub.pig

结果:

load('foo');

但尝试从命令行提供值:

pig -p myParam=bar -r testSub.pig

抛出错误:

2013-04-23 13:37:27,531 [main] ERROR org.apache.pig.Main - ERROR 2999: Unexpected internal error. Encountered unexpected arguments on command line - please check the command line.
Details at logfile: C:\Hadoop\hadoop-1.1.0-SNAPSHOT\logs\pig_1366720647495.log

并且日志文件说的相同:

Error before Pig is launched
----------------------------
ERROR 2999: Unexpected internal error. Encountered unexpected arguments on command line - please check the command line.

java.lang.RuntimeException: Encountered unexpected arguments on command line - please check the command line.
    at org.apache.pig.Main.run(Main.java:500)
    at org.apache.pig.Main.main(Main.java:111)
================================================================================

我尝试过使用“-param”,将内容放入单引号和双引号中,移动顺序,但没有运气。任何想法接下来要尝试的是 - 我需要在Windows命令提示符上添加一些奇怪的转义吗?

2 个答案:

答案 0 :(得分:0)

你的-p参数很好。您需要指定-x local -r -f <file>,例如:

> pig -p myParam=bar -x local -r -f testSub.pig

-x local标志指示pig在没有mapreduce集群的情况下在本地运行。

答案 1 :(得分:0)

自HDInsight发布0.4(3月25日)以来,我遇到了同样的问题。我还通过直接在脚本中放置参数值来验证脚本(工作正常)。因此,它可能是一个“窗口”的东西。一种解决方法是将参数放在参数文件(myparamfile.txt)中,并使用以下参数进行引用:

    > pig -f testsub.pig -m myparamfile.txt