Hive中创建表及数据导入/导出

相关考试内容

1、启动集群
.......

2、hive中创建表
例:
create table mytable(name string,salary float)row format delimited fields terminated by',';

3、从本地文件中载入数据
load data local inpath '/root/experiment/datas/hive/file1.txt' overwrite into table mytable;

4、查看表中是否有数据
...........

5、TopN查询
select * from mytable sort by age desc limit3;

6、去除重复记录(可能会考)
select distinct id,name from mytable;

7、将mytable查询结果放入另一个表(可能会考)
create table result as select avg(salary) from mytable;

8、将结果存入本地文件
insert overwrite local directory '/root/res' row format delimited fields terminated by ',' select avg(salary) from mytable;

9、将结果存入集群目录中
insert overwrite directory '/sw' row format delimited fields terminated by ',' select *from member order by age desc limit3;

/**********/
1、启动集群
start-dfs.sh
start-yarn.sh

2.Hive中创建表
在本地~目录下建立文本文件stu.txt,录入10位本班同学的信息(学号,姓名,性别,年龄)

3、进入Hive,创建表mytable
hive> create table mytable(id int,name string,gender string,age int) row format delimited fields terminated by '\t';

4、将本地文件stu.txt的数据导入到表mytable中
hive> load data local inpath '/root/stu.txt' overwrite into table mytable;

5、在HDFS中查看文件信息
hive> dfs -ls -R /data/hive/warehouse;
hive> dfs -cat /data/hive/warehouse/mytable/stu.txt;

6、在指定位置(/自己姓名字母缩写)创建表
hive> create table t1(id int,name string) location '/自己姓名字母缩写/t1';

7、创建表t2的同时加载数据,数据间隔用逗号
hive> create table t2 row format delimited fields terminated by ',' as select * from mytable;

8、在指定位置(/自己姓名字母缩写/t3)创建表t3的同时加载数据(学号和姓名两列,性别为女),数据间隔用冒号

create table t3 row format delimited fields terminated by':' location '/sw/t3' as select id,name from mytable where gender='female';

posted @ 2020-12-17 15:30  bky000001  阅读(963)  评论(0)    收藏  举报