hive的数据分为两部分,一部分是真实的数据文件,存放在hdfs上,另一份是真实数据的元数据(即数据的描述信息,比如说存储位置、时间、大小之类的),一般存放在mysql中,存放的配置可以修改hive-site.xml来完成:

表结构可以参考博客:[一起学Hive]之十四-Hive的元数据表结构详解 - 1130136248 - 博客园
1、hive版本表
version:存储hive的版本信息的表,有且只能有一条记录,多或者少都不行

2、数据库相关的表

dbs是主表,其他表都是从表,根据DB_ID关联。其中tbls表也是dbs的从表,tbls表的从表也很多就不在这里显示了
dbs示例数据:

data_params示例数据(创建表的时候指定的创建者和创建时间):

funcs示例数据(自定义方法相关描述):

func_ru示例数据:

3、表相关的表

tbls是表的主体部分,包括表名称、表的创建时间、所属数据库的id、所在目录等信息,示例数据如下:

table_params示例数据,这里存放表的相关属性信息:

partitions示例数据:

partition_keys示例数据:

idxs、tbl_col_privs、tbl_col_stats、tbl_privs表没数据。
4、分区相关

partition_params表示例数据:

partition_params示例数据:

part_privs、part_col_stats、part_col_privs无数据
5、文件相关

sds示例数据:

columns_v2示例数据:

serdes示例数据:

serde_params示例数据:

元数据操作需求:
再不适用hive相关的客户端和其他类似直接操作hive的工具的情况下,删除一张表(test.a),如下:

操作步骤如下:
第一步:根据表名和库名查询得出TBL_ID、SD_ID、PART_ID、CD_ID、SERDE_ID
SELECT
t.TBL_ID,t.SD_ID,p.PART_ID,s.CD_ID,s.SERDE_ID
FROM
(
SELECT
tt.TBL_ID,
tt.SD_ID
FROM
tbls tt,
dbs d
WHERE
d.DB_ID = tt.DB_ID
AND d.`NAME` = 'test'
AND tt.TBL_NAME = 'a'
) t
LEFT JOIN sds s ON t.sd_id = s.SD_ID
LEFT JOIN `partitions` p on t.TBL_ID=p.TBL_ID
结果如下:

第二步:按照顺序依次执行删除数据语句(要先删除子表数据)
先删除partition相关的(选的实验表没有分区,假设有分区):
delete from partition_params where PART_ID=
delete from partition_key_vals where PART_ID=
part_privs,part_col_stats,part_col_privs //这几个表基本没有数据,可以不用管,如果有数据则必须删除,否则partitions因为外键关系无法删除对应数据
delete from partitions where PART_ID=
再删除tbls相关的
delete from table_params where TBL_ID=16
delete from partition_keys where TBL_ID=16
tbl_col_privs,tbl_privs,tab_col_stats,index_params,idxs的原理同上(注意idxs是index_params的主表)
delete from tbls where TBL_ID=16
最后删除sds相关
sd_params,bucketing_cols,skewed_string_list_values,skewed_col_names,skewed_values
这些都是sds的从表,需要先行删除,但是基本上都没有数据
delete from sds where SD_ID=16
删除cds相关
delete from columns_v2 where CD_ID=21
delete from cds where CD_ID=21
删除serdes相关
delete from serde_params where SERDE_ID=16
delete from serdes where SERDE_ID=16
删除结果:

网友评论