hive 中使用shell/python

来源:互联网 发布:数据挖掘常用软件 编辑:程序博客网 时间:2024/06/05 01:51

官方参考
国内参考

使用的技巧:TRANSFORM

在hive中使用shell或python,主要优点是减少用java编写udf的工作。这样就十分方便与字段一些处理。
官方参考对python的说明比较详细,shell较少,先上传一个shell的示例;

SHELL

#!/bin/bash# file name : convertDate.sh# function : convert date to a custom format date,i.e. 2015-12-10 15:23:23 to  2015-12-10 15:23:15, map seconds to 00,15,30,45;while read line; do   dt=`echo $line|awk -F'[:]' {s=$3-$3%15;if(s==0)s="00";print $1":"$2":"s}`   echo $dtdone

hive shell

hive << EOFadd file convertDate.shfrom( from online_behavior select transform(online_behavior.time) using 'convertDate.sh' as (ntime) where online_behavior.dt='2015-06-22')obinsert overwrite local directory '/home/user/etlProj/flowProj/t1.log'select ntime,count(*) group by ntime;EOF

注意:如果hive是按装在window上,using 之后要加上 cmd cmd.sh,linux上可以只写cmd.sh


0 0
原创粉丝点击