是否可以将参数的值传递给UDF构造函数?

问题描述:

我写了一个带有构造函数参数的UDF.

I've written a UDF which takes a constructor parameter.

我已经成功初始化并在grunt中将其用作

I've successfully initialized and used it in grunt as

grunt> register mylib.jar
grunt> define Function com.company.pig.udf.MyFunction('param-value');

但是我不能使用Pig参数来初始化它,

But I can't initialize it using a Pig parameter as in

grunt> define Decrypt com.company.pig.udf.MyFunction($secret);

grunt> define Decrypt com.company.pig.udf.MyFunction('$secret');

我试图同时使用-param-param_file选项初始化$secret.

I tried to initialize $secret using both -param and -param_file options.

是否完全支持 Pig参数作为UDF构造函数参数?

Are Pig parameters supported as UDF constructor arguments at all?

我正在加载的函数用于解密某些数据,并且param-value包含特殊字符,如%$!".但没有引号.所以我不确定是遇到值扩展问题还是参数没有扩展.

The function I'm loading is used to decrypt some data and the param-value contains special characters as "%$!" but no quotes. So I'm unsure whether I'm running into an value expansion issue or a parameter there is just not being expanded.

我正在参数文件中设置不带引号的参数值:

I'm setting the parameter value without quotes in a param file:

secret = My$ecr%t!

肯定可以将参数值传递给UDF.问题似乎出在$符号.

It is definitely possible to pass parameter values to UDFs. The problem seems to be the $ sign.

这应该是正确的语法:

define Decrypt com.company.pig.udf.MyFunction('$secret');

在您的参数文件中输入:

In your parameter file put:

secret=My\$ecr%t!

-dryrun选项可能会对此有所帮助,它将创建一个名为<nameofpigfile>.pig.subsituted的文件,而不运行实际的脚本.

The -dryrun option can be helpful for this it will create a file called <nameofpigfile>.pig.subsituted and not run the actual script.

pig -x local -dryrun -f mypigfile.pig -param_file myparameterfile

此外,您可能需要猪> = 0.11

Also, you probably need pig >= 0.11

https://issues.apache.org/jira/browse/PIG-2931