Hivepython also read into Python and handle external files in Python scripts txt

Source: Internet
Author: User

find the data row in the installation list for each GID in table Test_gid2 that contains the PKG name in the file pkgs. The pkgs file is to be placed under a path with the Python script. with transform incoming data, regardless of the original file delimiter, in Python processing is used "\ T" to deal with. Test_gid2 table contains fields: Gid,phone_model,usertags,installed_applist        tes4.py script content: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 #避免重复读入数据, once you have a match on the Pkg to exit this cycle, to match the next row of data Note: Add two files to hive, one is the py script, test4.py One is a text file Pkgs.txtSQL script: Select TRANSFORM(gid,phone_model,usertags,installed_applist) USING ' python test4.py 'As (gid,phone_model,usertags,installed_applist)From Test_gid2;=================pkgs.txt file content format, one line at a pkgname:

com.tencent.mm

Com.tencent.mobileqq

Cn.testin.allintest

Hivepython also read into Python and handle external files in Python scripts txt

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.