创建表
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;
将查询结果导入某表中
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)