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