[Solved-1 Solution] Hadoop Pig: Passing Command Line Arguments ?
What is command line arguments ?
- It is possible to pass arguments to programs when they are executed.
- We can indicate the input parameter on the command line and use that when we are loading.
Example:
Command Line:
Problem:
Is there a way to do this ? eg, pass the name of the file to be processed, etc ?
Solution 1:
In Command Line: We can use the following
- If there are few parameters then use -param (-p)
- If there are lot of parameters then use -param_file (-m)
We can use either approach depending on the nature of value of command line arguments, we can use -param when we developing and testing scripts. Once pig script is ready for batch processing or running thru crontab, we use -param_file so that if any change required, we can easily update the params.init file.
Pig will show all the available options.
- The sample code for student is given below
Employees .txt (input data)
Params.init (file to hold all parameters)
Filter.pig
1. Using params on command line (-param or -p) & Output
2. Using params file on command line (-param_file or -m)&Output
Note:
Use absolute path for file paths (both as parameters and when giving param file path to -param_file (-m)).