hivepython 同時讀入python 且python指令碼中處理外部檔案txt

來源:互聯網
上載者:User

標籤:bsp   span   欄位   tin   close   read   div   str   split   

 找出表test_gid2中每個gid的安裝列表中含有檔案pkgs中的pkg名字的資料行。pkgs檔案要與python指令碼放在一個路徑下。用 transform 的傳入資料的時候,不管原檔案分隔字元是什麼樣的,在python裡面處理都是用“\t”來處理。test_gid2表包含的欄位為:gid,phone_model,usertags,installed_applist        tes4.py指令碼內容: import codecsimport osimport reimport sys lt1=[ ]f1=codecs.open(‘pkgs.txt‘,‘r‘,‘utf-8‘)for i in f1.readlines():    line=i.strip()    lt1.append(line)f1.close() for lines in sys.stdin:    arr=lines.strip().split(‘\t‘)    pkgs=re.split(";|,",arr[-1])    for j in lt1:         if j in pkgs:             print ‘\t‘.join(arr)             break    #避免重複讀入資料,一旦有了匹配上的pkg就退出這次迴圈,去匹配下一行資料 注意:add 兩個檔案到hive中,一個是 py指令碼,test4.py  一個是文字檔 pkgs.txtsql指令碼: select TRANSFORM(gid,phone_model,usertags,installed_applist) USING ‘python test4.py‘as (gid,phone_model,usertags,installed_applist)from test_gid2 ;  =================pkgs.txt  檔案內容格式,一行一個pkgname:

com.tencent.mm

com.tencent.mobileqq

cn.testin.allintest 

hivepython 同時讀入python 且python指令碼中處理外部檔案txt

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.