[ 
https://issues.apache.org/jira/browse/PIG-2548?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13215079#comment-13215079
 ] 

Daniel Dai commented on PIG-2548:
---------------------------------

Command line arguments also works in PigRunner. Here is my understanding of the 
problem:

some.py:
{code}
P = Pig.compile("""A = load '$DATE' as (name, age, gpa);store A into 
'output';""")
Q = P.bind()
result = Q.runSingle()
if result.isSuccessful():
    print $DATE + " success"
else:
    print $DATE + " fail"
{code}

You want do a parameter substitution in pig:
pig -param DATE=20120223 some.py

This currently only replaces DATE in Pig script (first occurrence) but not in 
Python (second/third occurrence). However, extending parameter substitution to 
Python is not great since Python programmer does not think of parameter 
substitution. Here is my proposal to use command line arguments to solve the 
problem:

some.py:
{code}
DATE = sys.argv[1];
P = Pig.compile("A = load '" + DATE + "' as (name, age, gpa);store A into 
'output';")
Q = P.bind()
result = Q.runSingle()
if result.isSuccessful():
    print DATE + " success"
else:
    print DATE + " fail"
{code}

You can pass the command line arguments to Python:
pig some.py 20120223

                
> Support for providing parameters to python script
> -------------------------------------------------
>
>                 Key: PIG-2548
>                 URL: https://issues.apache.org/jira/browse/PIG-2548
>             Project: Pig
>          Issue Type: New Feature
>    Affects Versions: 0.9.1, 0.10
>            Reporter: Vivek Padmanabhan
>
> If I have an embedded pig script in python, there is no way to get user 
> passed parameters in the python script.
> Though PIG-2165 adds the capability of reading these params in the pig 
> script, from python it is still not possible.
> It would be nice to have this feature if I have some sort of post processing 
> happening in my python scrip based on the params.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to