hive删除表(hive常用命令)

精英怪
广告

在大数据学习当中,尤其是Hadoop生态的学习当中,Hive是必备的,也是相对门槛较低,比较好入手的一个组件。今天的大数据开发分享,和大家分享Hive的基础知识点。

hive删除表(hive常用命令)

Hive简介根据官方文档的定义,Hive是一种用类SQL语句来协助读写、管理那些存储在分布式存储系统上大数据集的数据仓库软件

1、进入hive数据库:

hive

2、查看hive中的所有数据库:

show databases;

3、用default数据库:

use default;

4、查看所有的表:

show tables;

5、查询表结构:

desc table_name(表名);

6、查询表数据:

select * from table_name(表名);

7、创建数据库:

hive> create schema shop_db;

8、验证数据库表:

hive> show databases;

9、删除数据库:

hive> drop database if exists shop_db;

drop schema shop_db;

全部删除相应的表在删除数据库之前:

hive> drop dataBASE if exists shop_db cascade;

10、创建表tb_employee

hive> create table if not exists tb_employee (id int,name string,salary string,destination string) > comment '员工信息详情表' > row format DELIMITED > fields terminated by '\t' > lines terminated by '\n' > stored as textfile;

如果增加分区必须在创建表的时候就创建分区,不然就会报错,创建分区的命令>partition by ‘根据哪个字段分区’,

hive> create table tb_employee (id int, name string, dept string) > PARTITIONED BY (year int) > row format delimited > fields terminated by '\t' > lines terminated by '\n' > stored as textfile;

stored as textfile文件格式,文件格式在hive中有三种: textfile、Sequencefile、Rcfile。

11、添加数据到表中

hive> load data local inpath '/usr/hadoop/hive/employee.txt' overwrite into table tb_employee;

如果table是个分区表则必须在hql中指定分区

hive> load data local inpath '/usr/hadoop/hive/employee.txt' overwrite into table tb_employee partition(year=2022);

load data:加载数据;

local:本地数据

inpath:文件的地址

overwrite:覆盖表中的数据,注意加overwrite是重写表的数据,不加是追加数据

插入表数据:insert into tb_employee(id,name) values (1,'洪生鹏');hive只支持插入不支持修改和删除

12、重命名表名:

hive> alter table tb_employee rename to emp;

13、修改tb_employee表中字段name为user_name:

hive> alter table tb_employee change name user_name string;

14、修改tb_employee表中字段salary的数据类型从float改为double:

hive> alter table tb_employee change salary salary double;

15、删除表

hive> drop table table_name;

16、创建视图

hive> create view employee_view as select * from tb_employee where salary>3000;

17、不同类型的连接 join 、left outer join 、right outer join 、full outer join

18、创建外部表:用external关键字

hive> create external table outside_table_name(name string comment '姓名',addr string comment '地址');

19、查询表信息:

desc formatted outside_table_name;

关于大数据开发,Hive基础知识点是必须要掌握的。

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
评论列表 (暂无评论,387人围观)

还没有评论,来说两句吧...