Hive DDL用于定义Hive数据库模型,其命令包括create、drop、alter、truncate、show、describe等,主要对数据库和表进行创建、修改、删除等操作。
数据库与表
创建数据库
create database empdb; show databases; use empdb;
修改数据库名
alter database empdb set dbproperties('name'='empdb_0520');
删除数据库
drop database empdb [restrict|cascade];
默认情况下使用restrict删除数据库。如果数据库非空,则使用restrict删除数据库会失败,此时需要cascade级联删除数据库。
创建表
create table employee_external( name string, work_place ARRAY<string>, sex_age STRUCT<sex:string,age:int>, skills_score MAP<string,int>, depart_title MAP<STRING,ARRAY<STRING>> ) partitioned by (year string,month string) row format delimited fields terminated by "|" lines terminated by "\n" stored as textfile;
分区:partitioned by
分桶:clostered by
分隔符设置开始语句:row format delimited
设置字段与字段之间的分隔符:fields terminated by
设置行与行之间的分隔符:lines terminated by
表中数据存储格式:stored as
查看表头:
describe employee_external;
修改表名
alter table employee_external[原表名] rename to employee[修改后表名];
增加一列
alter table employee add columns(empid string);
DDL其他常用命令
最后,本篇文章是基于我所学所知进行的知识总结,如有误论,虚心接受指正。参考文献是《Hadoop数据仓库实战》,感兴趣的小伙伴可以对其进行深入阅读。最近看了一部电视剧,叫“士兵突击”,感兴趣的小伙伴推荐看一看,里面每一个人物的塑造都值得去品鉴回味,整部剧情都贯彻了“不抛弃,不放弃”的精神内核,当你还不知道现在、未来怎么前进的时候,可以去看看这部剧。(2024/03/19)