您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關hive中python udf的示例分析的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
udfdata.txt:
aa pingpong,swim,running
create table udfdata(name String,hobby String) row format delimited fields terminated by '\t' ; LOAD DATA LOCAL INPATH '/Users/lifei/hivedata/udfdata.txt' OVERWRITE INTO TABLE udfdata; add file /Users/lifei/hivedata/parsehobby.py; select transform(name,hobby) using 'python parsehobby.py' as (name,hobby) from udfdata aa pingpong aa swim aa running add file /Users/lifei/hivedata/splithobby.py; select transform(hobby) using 'python splithobby.py' as (name,hobby,test) from udfdata; pingpong swim running
#parsehobby.py import sys for line in sys.stdin: detail = line.strip().split('\t') if (len(detail) < 2): continue name = detail[0] hobbis = detail[1] hobbyArray = hobbis.split(',') for hobby in hobbyArray: print "%s\t%s" %(name,hobby) #splithobby.py import sys for line in sys.stdin: detail = line.strip().split(',') print "%s\t%s\t%s" %(detail[0],detail[1],detail[2])
ps: explode和collect_set
中文或者str時報錯:'ascii' codec can't encode characters in position 61-62
reload(sys)
sys.setdefaultencoding('utf8')
感謝各位的閱讀!關于“hive中python udf的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。