首页 > 代码库 > hive 使用

hive 使用

参考资料

1. QuickStart  https://cwiki.apache.org/confluence/display/Hive/GettingStarted

2.Tutorial https://cwiki.apache.org/confluence/display/Hive/Tutorial

3.官方wiki https://cwiki.apache.org/confluence/display/Hive/Home

4.语法手册 https://cwiki.apache.org/confluence/display/Hive/LanguageManual

 

一.建表

CREATE EXTERNAL TABLE tablename(  xx1 string,   xx2 string,  xx3 int)ROW FORMAT DELIMITED   FIELDS TERMINATED BY , STORED AS INPUTFORMAT   org.apache.hadoop.mapred.TextInputFormat OUTPUTFORMAT   org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormatLOCATION  hdfs://xx/tablename;

 

二.插入操作

insert overwrite table tablename

 

三.数据类型转换操作

select cast(xx AS int) from tablename;

 

四.group by 操作

insert overwrite table a select a1,a2,a3,count(*) from b group by a1,a2,a3;

执行group by操作需要select那个字段group by就要有哪个字段

 

五.字符串split操作

select split(a1,",") from a;

split 操作生成一个列表