You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by "Duckworth, Will" <wd...@comscore.com> on 2012/06/18 23:19:05 UTC

Getting sys.argv using embedded jython

This has to be something obvious but I can’t seem to get python parameters once I add in a main().  Thanks.

~/pig-0.10/bin/pig pytest.py haha
...
2012-06-18 17:11:50,312 [main] INFO  org.apache.pig.scripting.jython.JythonScriptEngine - created tmp python.cachedir=/tmp/pig_jytho
n_9083561197267275440
haha

~/pig-0.10/bin/pig pytest2.py haha
...
2012-06-18 17:13:25,609 [main] INFO  org.apache.pig.scripting.jython.JythonScriptEngine - Register scripting UDF: main
2012-06-18 17:13:25,635 [main] ERROR org.apache.pig.Main - ERROR 1121: Python Error. Traceback (most recent call last):
  File "/home/wduckworth/pytest2.py", line 11, in <module>
    print sys.argv[1]
IndexError: index out of range: 1

* * * pytest.py

#!/usr/bin/python

import sys
from org.apache.pig.scripting import Pig
print sys.argv[1]

* * * pytest2.py

#!/usr/bin/python

import sys
from org.apache.pig.scripting import Pig

def main():
    print sys.argv[1]

if __name__ == '__main__':
    main()




Will Duckworth Senior Vice President, Software Engineering | comScore, Inc. (NASDAQ:SCOR)

o +1 (703) 438-2108 | m +1 (301) 606-2977 | wduckworth@comscore.com<ma...@comscore.com>

...........................................................................................................

Introducing Mobile Metrix 2.0 - The next generation of mobile behavioral measurement
www.comscore.com/MobileMetrix<http://www.comscore.com/Products_Services/Product_Index/Mobile_Metrix_2.0>



Re: Getting sys.argv using embedded jython

Posted by Daniel Dai <da...@hortonworks.com>.
Go ahead

On Tue, Jun 19, 2012 at 3:10 PM, Duckworth, Will <wd...@comscore.com>wrote:

> Confirmed that it works with trunk. Want me to log a ticket against 0.10?
>
> On Jun 19, 2012, at 5:09 PM, "Duckworth, Will" <wd...@comscore.com>
> wrote:
>
> > Thanks Daniel. I will get a build of trunk and test as well.
> >
> > On Jun 19, 2012, at 4:53 PM, "Daniel Dai" <da...@hortonworks.com> wrote:
> >
> >> Yes, I can see this. However, trunk runs fine for me. I don't yet know
> why
> >> was that.
> >>
> >> Daniel
> >>
> >> On Mon, Jun 18, 2012 at 2:52 PM, Duckworth, Will <
> wduckworth@comscore.com>wrote:
> >>
> >>> I tried a couple other versions.
> >>>
> >>> This will work:
> >>>
> >>> #!/usr/bin/python
> >>>
> >>> import sys
> >>>
> >>> from org.apache.pig.scripting import Pig
> >>>
> >>> if __name__ == '__main__':
> >>>  print sys.argv[1]
> >>>
> >>>
> >>> This will not:
> >>>
> >>> #!/usr/bin/python
> >>>
> >>> import sys
> >>>
> >>> from org.apache.pig.scripting import Pig
> >>>
> >>> @outputSchema("ip_address:long")
> >>> def Ip2Num(ip):
> >>>  pass
> >>>
> >>> if __name__ == '__main__':
> >>>  print sys.argv[1]
> >>>
> >>>
> >>>
> >>>
> >>> Will Duckworth  Senior Vice President, Software Engineering  |
> comScore,
> >>> Inc.(NASDAQ:SCOR)
> >>> o +1 (703) 438-2108 | m +1 (301) 606-2977 | mailto:
> wduckworth@comscore.com
> >>>
> >>>
> .....................................................................................................
> >>> -----Original Message-----
> >>> From: Duckworth, Will [mailto:wduckworth@comscore.com]
> >>> Sent: Monday, June 18, 2012 5:19 PM
> >>> To: user@pig.apache.org
> >>> Subject: Getting sys.argv using embedded jython
> >>>
> >>> This has to be something obvious but I can’t seem to get python
> parameters
> >>> once I add in a main().  Thanks.
> >>>
> >>> ~/pig-0.10/bin/pig pytest.py haha
> >>> ...
> >>> 2012-06-18 17:11:50,312 [main] INFO
> >>> org.apache.pig.scripting.jython.JythonScriptEngine - created tmp
> >>> python.cachedir=/tmp/pig_jytho
> >>> n_9083561197267275440
> >>> haha
> >>>
> >>> ~/pig-0.10/bin/pig pytest2.py haha
> >>> ...
> >>> 2012-06-18 17:13:25,609 [main] INFO
> >>> org.apache.pig.scripting.jython.JythonScriptEngine - Register scripting
> >>> UDF: main
> >>> 2012-06-18 17:13:25,635 [main] ERROR org.apache.pig.Main - ERROR 1121:
> >>> Python Error. Traceback (most recent call last):
> >>> File "/home/wduckworth/pytest2.py", line 11, in <module>
> >>>  print sys.argv[1]
> >>> IndexError: index out of range: 1
> >>>
> >>> * * * pytest.py
> >>>
> >>> #!/usr/bin/python
> >>>
> >>> import sys
> >>> from org.apache.pig.scripting import Pig
> >>> print sys.argv[1]
> >>>
> >>> * * * pytest2.py
> >>>
> >>> #!/usr/bin/python
> >>>
> >>> import sys
> >>> from org.apache.pig.scripting import Pig
> >>>
> >>> def main():
> >>>  print sys.argv[1]
> >>>
> >>> if __name__ == '__main__':
> >>>  main()
> >>>
> >>>
> >>>
> >>>
> >>> Will Duckworth Senior Vice President, Software Engineering | comScore,
> >>> Inc. (NASDAQ:SCOR)
> >>>
> >>> o +1 (703) 438-2108 | m +1 (301) 606-2977 | wduckworth@comscore.com
> >>> <ma...@comscore.com>
> >>>
> >>>
> >>>
> ...........................................................................................................
> >>>
> >>> Introducing Mobile Metrix 2.0 - The next generation of mobile
> behavioral
> >>> measurement
> >>> www.comscore.com/MobileMetrix<
> >>>
> http://www.comscore.com/Products_Services/Product_Index/Mobile_Metrix_2.0>
> >>>
> >>>
> >>>
>

Re: Getting sys.argv using embedded jython

Posted by "Duckworth, Will" <wd...@comscore.com>.
Confirmed that it works with trunk. Want me to log a ticket against 0.10?

On Jun 19, 2012, at 5:09 PM, "Duckworth, Will" <wd...@comscore.com> wrote:

> Thanks Daniel. I will get a build of trunk and test as well. 
> 
> On Jun 19, 2012, at 4:53 PM, "Daniel Dai" <da...@hortonworks.com> wrote:
> 
>> Yes, I can see this. However, trunk runs fine for me. I don't yet know why
>> was that.
>> 
>> Daniel
>> 
>> On Mon, Jun 18, 2012 at 2:52 PM, Duckworth, Will <wd...@comscore.com>wrote:
>> 
>>> I tried a couple other versions.
>>> 
>>> This will work:
>>> 
>>> #!/usr/bin/python
>>> 
>>> import sys
>>> 
>>> from org.apache.pig.scripting import Pig
>>> 
>>> if __name__ == '__main__':
>>>  print sys.argv[1]
>>> 
>>> 
>>> This will not:
>>> 
>>> #!/usr/bin/python
>>> 
>>> import sys
>>> 
>>> from org.apache.pig.scripting import Pig
>>> 
>>> @outputSchema("ip_address:long")
>>> def Ip2Num(ip):
>>>  pass
>>> 
>>> if __name__ == '__main__':
>>>  print sys.argv[1]
>>> 
>>> 
>>> 
>>> 
>>> Will Duckworth  Senior Vice President, Software Engineering  | comScore,
>>> Inc.(NASDAQ:SCOR)
>>> o +1 (703) 438-2108 | m +1 (301) 606-2977 | mailto:wduckworth@comscore.com
>>> 
>>> .....................................................................................................
>>> -----Original Message-----
>>> From: Duckworth, Will [mailto:wduckworth@comscore.com]
>>> Sent: Monday, June 18, 2012 5:19 PM
>>> To: user@pig.apache.org
>>> Subject: Getting sys.argv using embedded jython
>>> 
>>> This has to be something obvious but I can’t seem to get python parameters
>>> once I add in a main().  Thanks.
>>> 
>>> ~/pig-0.10/bin/pig pytest.py haha
>>> ...
>>> 2012-06-18 17:11:50,312 [main] INFO
>>> org.apache.pig.scripting.jython.JythonScriptEngine - created tmp
>>> python.cachedir=/tmp/pig_jytho
>>> n_9083561197267275440
>>> haha
>>> 
>>> ~/pig-0.10/bin/pig pytest2.py haha
>>> ...
>>> 2012-06-18 17:13:25,609 [main] INFO
>>> org.apache.pig.scripting.jython.JythonScriptEngine - Register scripting
>>> UDF: main
>>> 2012-06-18 17:13:25,635 [main] ERROR org.apache.pig.Main - ERROR 1121:
>>> Python Error. Traceback (most recent call last):
>>> File "/home/wduckworth/pytest2.py", line 11, in <module>
>>>  print sys.argv[1]
>>> IndexError: index out of range: 1
>>> 
>>> * * * pytest.py
>>> 
>>> #!/usr/bin/python
>>> 
>>> import sys
>>> from org.apache.pig.scripting import Pig
>>> print sys.argv[1]
>>> 
>>> * * * pytest2.py
>>> 
>>> #!/usr/bin/python
>>> 
>>> import sys
>>> from org.apache.pig.scripting import Pig
>>> 
>>> def main():
>>>  print sys.argv[1]
>>> 
>>> if __name__ == '__main__':
>>>  main()
>>> 
>>> 
>>> 
>>> 
>>> Will Duckworth Senior Vice President, Software Engineering | comScore,
>>> Inc. (NASDAQ:SCOR)
>>> 
>>> o +1 (703) 438-2108 | m +1 (301) 606-2977 | wduckworth@comscore.com
>>> <ma...@comscore.com>
>>> 
>>> 
>>> ...........................................................................................................
>>> 
>>> Introducing Mobile Metrix 2.0 - The next generation of mobile behavioral
>>> measurement
>>> www.comscore.com/MobileMetrix<
>>> http://www.comscore.com/Products_Services/Product_Index/Mobile_Metrix_2.0>
>>> 
>>> 
>>> 

Re: Getting sys.argv using embedded jython

Posted by "Duckworth, Will" <wd...@comscore.com>.
Thanks Daniel. I will get a build of trunk and test as well. 

On Jun 19, 2012, at 4:53 PM, "Daniel Dai" <da...@hortonworks.com> wrote:

> Yes, I can see this. However, trunk runs fine for me. I don't yet know why
> was that.
> 
> Daniel
> 
> On Mon, Jun 18, 2012 at 2:52 PM, Duckworth, Will <wd...@comscore.com>wrote:
> 
>> I tried a couple other versions.
>> 
>> This will work:
>> 
>> #!/usr/bin/python
>> 
>> import sys
>> 
>> from org.apache.pig.scripting import Pig
>> 
>> if __name__ == '__main__':
>>   print sys.argv[1]
>> 
>> 
>> This will not:
>> 
>> #!/usr/bin/python
>> 
>> import sys
>> 
>> from org.apache.pig.scripting import Pig
>> 
>> @outputSchema("ip_address:long")
>> def Ip2Num(ip):
>>   pass
>> 
>> if __name__ == '__main__':
>>   print sys.argv[1]
>> 
>> 
>> 
>> 
>> Will Duckworth  Senior Vice President, Software Engineering  | comScore,
>> Inc.(NASDAQ:SCOR)
>> o +1 (703) 438-2108 | m +1 (301) 606-2977 | mailto:wduckworth@comscore.com
>> 
>> .....................................................................................................
>> -----Original Message-----
>> From: Duckworth, Will [mailto:wduckworth@comscore.com]
>> Sent: Monday, June 18, 2012 5:19 PM
>> To: user@pig.apache.org
>> Subject: Getting sys.argv using embedded jython
>> 
>> This has to be something obvious but I can’t seem to get python parameters
>> once I add in a main().  Thanks.
>> 
>> ~/pig-0.10/bin/pig pytest.py haha
>> ...
>> 2012-06-18 17:11:50,312 [main] INFO
>> org.apache.pig.scripting.jython.JythonScriptEngine - created tmp
>> python.cachedir=/tmp/pig_jytho
>> n_9083561197267275440
>> haha
>> 
>> ~/pig-0.10/bin/pig pytest2.py haha
>> ...
>> 2012-06-18 17:13:25,609 [main] INFO
>> org.apache.pig.scripting.jython.JythonScriptEngine - Register scripting
>> UDF: main
>> 2012-06-18 17:13:25,635 [main] ERROR org.apache.pig.Main - ERROR 1121:
>> Python Error. Traceback (most recent call last):
>> File "/home/wduckworth/pytest2.py", line 11, in <module>
>>   print sys.argv[1]
>> IndexError: index out of range: 1
>> 
>> * * * pytest.py
>> 
>> #!/usr/bin/python
>> 
>> import sys
>> from org.apache.pig.scripting import Pig
>> print sys.argv[1]
>> 
>> * * * pytest2.py
>> 
>> #!/usr/bin/python
>> 
>> import sys
>> from org.apache.pig.scripting import Pig
>> 
>> def main():
>>   print sys.argv[1]
>> 
>> if __name__ == '__main__':
>>   main()
>> 
>> 
>> 
>> 
>> Will Duckworth Senior Vice President, Software Engineering | comScore,
>> Inc. (NASDAQ:SCOR)
>> 
>> o +1 (703) 438-2108 | m +1 (301) 606-2977 | wduckworth@comscore.com
>> <ma...@comscore.com>
>> 
>> 
>> ...........................................................................................................
>> 
>> Introducing Mobile Metrix 2.0 - The next generation of mobile behavioral
>> measurement
>> www.comscore.com/MobileMetrix<
>> http://www.comscore.com/Products_Services/Product_Index/Mobile_Metrix_2.0>
>> 
>> 
>> 

Re: Getting sys.argv using embedded jython

Posted by Daniel Dai <da...@hortonworks.com>.
Yes, I can see this. However, trunk runs fine for me. I don't yet know why
was that.

Daniel

On Mon, Jun 18, 2012 at 2:52 PM, Duckworth, Will <wd...@comscore.com>wrote:

> I tried a couple other versions.
>
> This will work:
>
> #!/usr/bin/python
>
> import sys
>
> from org.apache.pig.scripting import Pig
>
> if __name__ == '__main__':
>    print sys.argv[1]
>
>
> This will not:
>
> #!/usr/bin/python
>
> import sys
>
> from org.apache.pig.scripting import Pig
>
> @outputSchema("ip_address:long")
> def Ip2Num(ip):
>    pass
>
> if __name__ == '__main__':
>    print sys.argv[1]
>
>
>
>
> Will Duckworth  Senior Vice President, Software Engineering  | comScore,
> Inc.(NASDAQ:SCOR)
> o +1 (703) 438-2108 | m +1 (301) 606-2977 | mailto:wduckworth@comscore.com
>
> .....................................................................................................
> -----Original Message-----
> From: Duckworth, Will [mailto:wduckworth@comscore.com]
> Sent: Monday, June 18, 2012 5:19 PM
> To: user@pig.apache.org
> Subject: Getting sys.argv using embedded jython
>
> This has to be something obvious but I can’t seem to get python parameters
> once I add in a main().  Thanks.
>
> ~/pig-0.10/bin/pig pytest.py haha
> ...
> 2012-06-18 17:11:50,312 [main] INFO
>  org.apache.pig.scripting.jython.JythonScriptEngine - created tmp
> python.cachedir=/tmp/pig_jytho
> n_9083561197267275440
> haha
>
> ~/pig-0.10/bin/pig pytest2.py haha
> ...
> 2012-06-18 17:13:25,609 [main] INFO
>  org.apache.pig.scripting.jython.JythonScriptEngine - Register scripting
> UDF: main
> 2012-06-18 17:13:25,635 [main] ERROR org.apache.pig.Main - ERROR 1121:
> Python Error. Traceback (most recent call last):
>  File "/home/wduckworth/pytest2.py", line 11, in <module>
>    print sys.argv[1]
> IndexError: index out of range: 1
>
> * * * pytest.py
>
> #!/usr/bin/python
>
> import sys
> from org.apache.pig.scripting import Pig
> print sys.argv[1]
>
> * * * pytest2.py
>
> #!/usr/bin/python
>
> import sys
> from org.apache.pig.scripting import Pig
>
> def main():
>    print sys.argv[1]
>
> if __name__ == '__main__':
>    main()
>
>
>
>
> Will Duckworth Senior Vice President, Software Engineering | comScore,
> Inc. (NASDAQ:SCOR)
>
> o +1 (703) 438-2108 | m +1 (301) 606-2977 | wduckworth@comscore.com
> <ma...@comscore.com>
>
>
> ...........................................................................................................
>
> Introducing Mobile Metrix 2.0 - The next generation of mobile behavioral
> measurement
> www.comscore.com/MobileMetrix<
> http://www.comscore.com/Products_Services/Product_Index/Mobile_Metrix_2.0>
>
>
>

RE: Getting sys.argv using embedded jython

Posted by "Duckworth, Will" <wd...@comscore.com>.
I tried a couple other versions.

This will work:

#!/usr/bin/python

import sys

from org.apache.pig.scripting import Pig

if __name__ == '__main__':
    print sys.argv[1]


This will not:

#!/usr/bin/python

import sys

from org.apache.pig.scripting import Pig

@outputSchema("ip_address:long")
def Ip2Num(ip):
    pass

if __name__ == '__main__':
    print sys.argv[1]




Will Duckworth  Senior Vice President, Software Engineering  | comScore, Inc.(NASDAQ:SCOR)
o +1 (703) 438-2108 | m +1 (301) 606-2977 | mailto:wduckworth@comscore.com
.....................................................................................................
-----Original Message-----
From: Duckworth, Will [mailto:wduckworth@comscore.com]
Sent: Monday, June 18, 2012 5:19 PM
To: user@pig.apache.org
Subject: Getting sys.argv using embedded jython

This has to be something obvious but I can’t seem to get python parameters once I add in a main().  Thanks.

~/pig-0.10/bin/pig pytest.py haha
...
2012-06-18 17:11:50,312 [main] INFO  org.apache.pig.scripting.jython.JythonScriptEngine - created tmp python.cachedir=/tmp/pig_jytho
n_9083561197267275440
haha

~/pig-0.10/bin/pig pytest2.py haha
...
2012-06-18 17:13:25,609 [main] INFO  org.apache.pig.scripting.jython.JythonScriptEngine - Register scripting UDF: main
2012-06-18 17:13:25,635 [main] ERROR org.apache.pig.Main - ERROR 1121: Python Error. Traceback (most recent call last):
  File "/home/wduckworth/pytest2.py", line 11, in <module>
    print sys.argv[1]
IndexError: index out of range: 1

* * * pytest.py

#!/usr/bin/python

import sys
from org.apache.pig.scripting import Pig
print sys.argv[1]

* * * pytest2.py

#!/usr/bin/python

import sys
from org.apache.pig.scripting import Pig

def main():
    print sys.argv[1]

if __name__ == '__main__':
    main()




Will Duckworth Senior Vice President, Software Engineering | comScore, Inc. (NASDAQ:SCOR)

o +1 (703) 438-2108 | m +1 (301) 606-2977 | wduckworth@comscore.com<ma...@comscore.com>

...........................................................................................................

Introducing Mobile Metrix 2.0 - The next generation of mobile behavioral measurement
www.comscore.com/MobileMetrix<http://www.comscore.com/Products_Services/Product_Index/Mobile_Metrix_2.0>