以前所有的Hive 函数都是 Java 或是 Scala 语言写的 ,Python 没有弄个 ,看到Python 格式的 code 懵逼了 ,非常懵逼
今天在看 Python 正则表达式偶遇 Python udf 的一个 case ,不过 Python 484 not support udaf or udtf ?? I have know idea now .fuck
Here is the case :
there is one table named mytable and one column named your_name (last_name first_name )
and we want to split this column into two from one
Init:
mytable :
your_name
huchihaihe fuck
Finally :
mytable :
your_lastname your_firstname
huchihaihe fuck
#!/usr/bin/python3
import sys
for line in sys.stdin:
line=line.strip()
lname ,fname=line.split(' ') # space
l_name=lname.lower()
print('\t'.join([str(l_name),fname]))
#this it
the code represented the udf function to split a data into 2
Oky I admitted I fucked for the above print function why you need this ,sorry I do not know ,but it needed
Okay let's skip the question and see what we can do using the script
select your_name ,transform(your_name) using 'the above script path and name.py' as (l_name,fname) from mytable
Here we will get the result we wantted funny heng
I totally fucked