简体   繁体   English

将功能参数传递给Pig

[英]Pass function parameter to Pig

Here is my problem with Apache Pig, I run Pig script in a Python script. 这是我对Apache Pig的问题,我在Python脚本中运行Pig脚本。 There is a field called priority in Pig, whose value is either a random number, or just null. Pig中有一个称为优先级的字段,其值可以是随机数,也可以是null。 Each record of input should have a different random number. 输入的每个记录应具有不同的随机数。 Python code would determine between random number and null before call Pig script. Python代码将在调用Pig脚本之前确定随机数和null之间。

Scenario one: pig -param param1="" -f my_pig_script.pig 方案一:猪-param param1 =“” -f my_pig_script.pig

scenario two(just guess): pig -function param1=random() -f my_pig_script.pig 场景二(只是猜测):pig -function param1 = random()-f my_pig_script.pig

How two write right Pig script under scenario two? 如何在第二种情况下正确编写Pig脚本?

Thanks 谢谢

One thing is for sure - you do not need to (actually should not) pass random() as param, as it would pass ONLY 1 RANDOM NUMBER as param, which you do not want. 可以肯定的是,您不需要(实际上不应该)将random()作为参数传递,因为它将仅传递1个不需要的随机数作为参数。 The question is how to convey your PIG script to use null or random. 问题是如何传达您的PIG脚本以使用null或random。 Go ahead and pass null or non-null value to param1, pass non-null when you want pig script to use random instead of null. 继续并将null或非null值传递给param1,当您希望Pig脚本使用random而不是null时传递non-null。

Inside PIG script, you can use ternary operator as below: 在PIG脚本中,您可以使用三元运算符,如下所示:

A = FOREACH B GENERATE param1 IS NULL ? NULL : RANDOM();

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM