hive 命令

来源:互联网 发布:java虚拟机apk 编辑:程序博客网 时间:2024/05/16 18:39

创建表

create cite(citing int,cited int)                                                        ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ';  //此处我本来写的分隔符是/t 但是就是一直null 后来改成' 'ok

导入hdfs数据

load data  inpath 'hdfs://master:54310/user/root/cite.txt'  overwrite into table cite;

导入本地

oad data  local inpath '/usr/local/hadoop/hive/cite.txt'  overwrite into table cite; 

// 这个是本地文档。。在服务器那边。。错了很多次。。不是我用的windows主机


将查询结果导入某表中

insert overwrite table cite_count     select cited ,count(citing)     from cite     group by cited;

删除表

drop table +表名

查询表行数

select count(1) from+表名


创建分区列以及桶分布

create table page (vie int,useid int,ip string comment 'ip address of the use') comment 'this is the page view table'

partitioned by (dt string,country string)      //分区列 
clustered by (useid) into 32 buckets row format //桶
delimited fields terminated by ' ' lines terminated by '\n'  //读取条件 
STORED AS textfile;                                  //文本格式

导入数据

load data inpath 'hdfs://master:54310/user/root/page.txt' overwrite into table page 
partition (dt='2014.3.20',country='china');                 //分区条件

查询表

desc + 表名

更改表名

alter table page rename to pag;OK

增加新的列

alter table page add columns (newcol string);

删除一个分区

alter table page drop partition (dt=‘2014.3.20’);


连接操作

SELECT abc.* FROM abc JOIN cite  ON (abc.aa = cite.citing); 


SELECT a.val, b.val, c.val FROM a JOIN b ON (a.key = b.key1) JOIN c ON (c.key = b.key2)  




0 0