现在的位置: 首页 > 综合 > 正文

hive 基本操作

2013年01月07日 ⁄ 综合 ⁄ 共 1190字 ⁄ 字号 评论关闭

看了几遍,总也记不住,在此记录一下基本的HIVE操作

1.show tables;

列出所有的表

2.show tables '.user*';

列出正则匹配的所有表--------------------' . '为任意一个字符,' * '为多个字符

3.drop table 'hiveTest';

删除表

4.create table student(sid int,sname string);

创建表(不带索引)

5.create talbe student(sid int , sname string) partitioned by (ds string);

创建表(带索引)--------------------等同于分库表

6.alter table student rename to student2;

重命名表

7.alter table student add columns(sage int comment 'the student's age');

增加列

8.desc student;

查看表结构

9.create table student(sid int , sname string, sage int) partitioned by (ds string) row format delimited fields terminated by '\t' stored as textfile;

创建表,按'ds'进行分区,用'tab键作为对文件中的行进行分割的依据,文件的存储类型为TEXTFIEL------------------注意是'\t',不能是'/t';

10.show partitions student;

查看表的分区信息

11.load data local inpath '/home/hadoop/input/student.txt' overwrite into table student partition (ds=1);

将文件导入到HIVE表中-----------加local,用本地文件,不加local,用hdfs上文件;不加overwrite,追加数据,加overwrite,重写表数据----------对于本地文件,直接传到HIVE的HDFS上,但是,对于HDFS上的文件要导入,会将HDFS上的文件移动到HIVE对应的HDFS目录中。如果有重名的,不加OVERWRITE ,会将HDFS上的文件重命名,并报错,数据导入也会失败,很奇怪的现象

12.insert overwrite table student2 select * from student;

将查询结果插入到student2中,加overwrite会重写student2表数据

13.insert overwrite local directory '/home/hadoop/out' select * from student;

将查询结果插入到文件中,加overwrite会重写文件,否则会追加;加local会写到本地,否则会写的HDFS中

 

抱歉!评论已关闭.