Invoke Pig Latin script from other Pig script
Asked Answered
D

2

4

I have a question about PIG Latin. Is there any way how to invoke some pig script from the other pig script?

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;

Do you know if there is any functionality like this? Or any UDF?

Thank you and have a good day...

Diminution answered 17/12, 2013 at 13:52 Comment(0)
A
4

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).

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.

Apoenzyme answered 17/12, 2013 at 14:29 Comment(2)
Thanks a lot Winnie. I think this is great practice how to operate with Pig scripts.Automatic
A few other notes: 1- shared startup commands in /home/<username>/.pigbootup will be executed automatically (without requiring RUN). 2- RUN will have the additional side-effect of putting each of the commands from the script in your grunt history (as if you had executed the commands from the script individually; EXEC leaves only the EXEC line in history.).Calorimeter
L
0

You can use Macros for such things: http://pig.apache.org/docs/r0.11.1/cont.html#macros

Labonte answered 17/12, 2013 at 13:59 Comment(1)
This is not the correct answer. Macros do enable some code re-usage but they are not the same thing as running an entire Pig script from within another.Apoenzyme

© 2022 - 2024 — McMap. All rights reserved.