Hive Python UDF

622 Views Asked by At

I am using this Python UDF script:

import sys
import collections 
import datetime
import re

try:
    for line in sys.stdin: 
        line=line.strip()
        number,sd=line.split('\t')
        sd=sd.lower()
        sd=sd.split(' ')
        new_sd_list=collections.OrderedDict(collections.Counter(sd))
        new_sd=' '.join(new_sd_list)
        print('\t'.join([str(number),str(new_sd])))
except:
    print(sys.exc_info())

While executing in Putty The below command.

SELECT TRANSFORM(number,shortdescription) USING 'python name.py' \
   AS (number,shortdescription) FROM table;

I am getting this error:

Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row {"number": "ABC00548","shortdescription":""Master data inconsistency check in India Optimizer."}

FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask MapReduce Jobs Launched: Stage-Stage-1: Map: 4 HDFS Read: 0 HDFS Write: 0 FAIL Total MapReduce CPU Time Spent: 0 msec

1

There are 1 best solutions below

0
On
import sys
import collections 
import datetime
import re

try:
    for line in sys.stdin: 
        line=line.strip()
        number,sd=line.split('\t')
        sd=sd.lower()
        sd=sd.split(' ')
        new_sd_list=collections.OrderedDict(collections.Counter(sd))
        new_sd=' '.join(new_sd_list)
        print('\t'.join([str(number),str(new_sd)])) #syntax error
except:
    print(sys.exc_info())