hive 分区表
Last updated on January 17, 2025 am
🧙 Questions
☄️ Ideas
创建分区表
CREATE TABLE IF NOT EXISTS ispong_db.users(
username STRING COMMENT 'comment for username',
age INT COMMENT 'comment for age'
)
COMMENT 'comment for users'
PARTITIONED BY ( sex STRING COMMENT 'comment for sex')
ROW FORMAT
DELIMITED FIELDS TERMINATED BY '\001'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
创建分区
如果想创建中文分区,需要修改mysql的字符集
alter table cdh_hive.PARTITIONS modify PART_NAME varchar(767) collate utf8_bin null;
alter table cdh_hive.PARTITION_KEY_VALS modify PART_KEY_VAL varchar(256) collate utf8_bin null;
-- 查询分区
show partitions ispong_db.users;
-- 添加表分区
alter table data.aaaad2 add partition(ds='男');
-- 删除表分区
alter table ispong_db.users drop partition(sex='女');
插入数据
插入数据的时候,会自动创建分区
insert into table ispong_db.users partition(sex='男') values ('ispong',18);
🔗 Links
hive 分区表
https://ispong.isxcode.com/hadoop/hive/hive 分区表/