是否可以将参数的值传递给 UDF 构造函数? [英] Is it possible to pass the value of a parameter to an UDF constructor?

查看:28
本文介绍了是否可以将参数的值传递给 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?

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

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 选项对此很有帮助,它会创建一个名为 .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

这篇关于是否可以将参数的值传递给 UDF 构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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