简体   繁体   中英

Pass function parameter to Pig

Here is my problem with Apache Pig, I run Pig script in a Python script. There is a field called priority in Pig, whose value is either a random number, or just null. Each record of input should have a different random number. Python code would determine between random number and null before call Pig script.

Scenario one: pig -param param1="" -f my_pig_script.pig

scenario two(just guess): pig -function param1=random() -f my_pig_script.pig

How two write right Pig script under scenario two?

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. The question is how to convey your PIG script to use null or 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.

Inside PIG script, you can use ternary operator as below:

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

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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