您的位置:首页 > 其它

HIVE学习与实践(二):根据partition建表,插表,where in 语法,concat用法

2016-11-14 21:05 651 查看

1. 脚本例子1

建表mytable,

partition 就是按 rcd_date 也就是 record date 时间来分区,

用’\t’ 作为row的分隔符。

create table if not exists mydb.mytable (
event         string        COMMENT'####'   ,
info_id       string        COMMENT'#### '  ,
session_id     string        COMMENT'###'
) partitioned by (rcd_date string) row format delimited fields terminated by '\t';


2. 脚本例子2

应用场景如下,假如mydb里有一张记录了所有用户操作某个app的log:app_event_log ,

如何把触发了我们关心的断点的相关信息提取出来呢?

首先,表app_event_log是 按 年月日,也就是 y,m,d 做partition的, 利用concat函数连接起来,构成‘20161111’这样的格式。

其次,语法where in,后面跟字符串的array (‘123456’,’2345’,’123’),只要是属于该array的都会被select出来。

最后,把select出来的对应信息, insert 插表mytable,根据partition rcd_date。

set mapred.job.queue.name=queue_****;

insert overwrite table mydb.mytable
partition (rcd_date='20161111')
select
event,info_id,session_id
mytable.app_event_log t1
where
info_id in ('123456','2345','123') and
concat(y,m,d)='${datestr}' ;


字符串连接函数:concat

语法: concat(string A, string B…)

返回值: string

说明:返回输入字符串连接后的结果,支持任意个输入字符串

举例:

hive> select concat(‘abc’,'def’,'gh’) from lxw_dual;

abcdefgh


简明的教程:

http://www.yiibai.com/hive/hiveql_select_where.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hive 脚本