hive进阶
- case-when-then-else
select id,name,age1,
case
when age1 < 18 then ‘小屁孩’
when age1 >=18 then ‘成年人’
else ‘aa’ end as age222222
from person;
hive server2
- 配置
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
<!-- hive server2绑定的主机名-->
<property>
<name>hive.server2.thrift.bind.host</name>
<value>bigdata.com</value>
</property>
<! hive server2的超时时间,默认是5000L-->
<property>
<name>hive.server2.long.polling.timeout</name>
<value>5000</value>
</property>
- 步骤
- 在服务端启动服务:bin/hive –service hiveserver2
- 将hive文件夹scp到客户端
- bin/beeline
- !connect jdbc:hive2://node-1:10000
- 输入虚拟机用户名和密码
- sql语句
hive数据存储
- 最长使用ORC
- 使用ORC
- 创建orc格式的表
create table person(id int,name STRING,age INT)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' stored as orc;
- insert into table person2 select * from person;
- 得到orc格式的数据
- 创建orc格式的表时可以直接location数据的位置
- 创建orc格式的表
mysql数据备份
- 备份
mysqldump -uroot -p123456 数据库名称 > /opt/aa
- 还原
mysql > source /opt/aa
hive语法unix_timestamp
- 将时间换算成一秒为单位的整数,
select unix_timestamp(trackTime) from track_log limit 10;
1440760499
select unix_timestamp('2015-08-28 19:15:59') from track_log limit 10;
1440760559
from_unixtime()转换为时间戳
select from_unixtime(1440760559) from track_log limit 10;
2015-08-28 19:15:59
hivevar和hiveconf传递变量
- hiveconf -f
文件:select * from hiveconf:namelimit h i v e c o n f : n a m e l i m i t {hiveconf:count};
命令行:bin/hive -hiveconf name=’test.person’ -hiveconf count=3 -f /opt/file.hql
hivevar -f
文件:select * from