从其他Pig脚本调用Pig Latin脚本 [英] Invoke Pig Latin script from other Pig script
问题描述
我有一个关于PIG Latin的问题。有没有办法如何从另一个猪脚本调用一些猪脚本?
I have a question about PIG Latin. Is there any way how to invoke some pig script from the other pig script?
我知道可以运行用户定义的函数(UDF),如:
I know it is possible to run user defined functions (UDFs) like:
REGISTER myudfs.jar;
A = LOAD 'student_data' AS (name: chararray, age: int, gpa: float);
B = FOREACH A GENERATE myudfs.UPPER(name);
DUMP B;
但它不适用于猪脚本。我们正在计算一些不同的客户参数,并且为了可读性和重用性,加载一些猪片段是非常好的,例如:
But it is not working for pig script. We are counting some different customer parameters and for readibility and reuse it would be great to load some pig snippets, something like:
REGISTER somepigscript.pig;
LOAD somepigscript.pig;
你知道是否有这样的功能吗?或任何UDF?
Do you know if there is any functionality like this? Or any UDF?
谢谢,祝你有个美好的一天...
Thank you and have a good day...
推荐答案
Pig有两个命令, RUN
和 EXEC
。它们的不同之处在于 RUN
将执行Pig脚本并将其别名和属性留给后续使用,而 EXEC
执行脚本并返回调用环境不变(但可以在HDFS上创建任何新文件)。
Pig has two commands, RUN
and EXEC
. They differ in that RUN
will execute the Pig script and leave its aliases and properties available for subsequent usage, while EXEC
simply executes the script and returns with the calling environment unaltered (but with any new files created on HDFS available).
例如,我有一组宏,罐和属性,我想在我写的每一个脚本的开始处设置。我不是每次都输入它们,而是将它放到Pig脚本中,并在脚本开始处调用 RUN /my/script.pig
。
For example, I have a collection of macros, jars, and properties that I want to set at the beginning of every single script I write. Rather than type them every time, I put that into a Pig script and call RUN /my/script.pig
at the beginning of my scripts.
这篇关于从其他Pig脚本调用Pig Latin脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!