Java.io.IOException:Broken Pipe

Source: Internet
Author: User

Hadoop Streaming Programming: The use of Python scripts to write map and reduce scripts requires attention to handling exceptions, such as:

#!/usr/bin/python
Import Sys
For Eachline in Sys.stdin:
Eachline = Eachline.strip ()
Seg = Eachline.split (' \x01 ')
If seg[1]== ' rpt_visit ' and seg[3]!= ':
ad_id = seg[3]
print '%s\t%d '% (ad_id, 1)
Else
Pass

       The above code at first glance there is no obvious problem, but the actual situation is often incomplete data, so after each row of data segmentation, before reading the array elements, you must first determine the length of the array, Otherwise, there may be an exception to the array out of bounds, make the following modifications, add the length to determine the condition:
       #!/usr/bin/python
Import sys
for Eachline in Sys.stdin:
    eachline = Eachline.strip ()
    Seg = eachline.split (' \ x01 ')
    if  len (Seg) >= 4 and seg[1]== ' Rpt_visit ' and seg[3]!= ':
   &N bsp;    ad_id = seg[3]
        print '%s\t%d '% (ad_id, 1)
&nb sp;   else:
       pass

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.