hive中的外部表可以智能地识别分区吗?

yshpjwxd  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(444)

我需要运行这个每当我需要挂载分区。有一种方法可以自动检测外部配置单元表中的分区,而不是我手动执行

ALTER TABLE TableName ADD IF NOT EXISTS PARTITION()location 'locationpath';
tvz2xvvm

tvz2xvvm1#

恢复分区(msck修复表)
https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#languagemanualddl-恢复分区(msckrepairtable)

MSCK REPAIR TABLE table_name;

分区将自动添加

u5i3ibmn

u5i3ibmn2#

使用动态分区,不需要手动创建目录。但是动态分区模式需要设置为nonstrict,默认情况下是strict

CREATE External TABLE profile (
userId int
)
PARTITIONED BY (city String)
location '/user/test/profile';

set hive.exec.dynamic.partition.mode=nonstrict;

hive> insert into profile partition(city) 
      select * from nonpartition;

hive> select * from profile;
OK
1   Chicago
1   Chicago
2   Orlando

在hdfs中

[cloudera@quickstart ~]$ hdfs dfs -ls /user/test/profile
Found 2 items
drwxr-xr-x   - cloudera supergroup          0 2016-08-26
22:40 /user/test/profile/city=Chicago
drwxr-xr-x   - cloudera supergroup          0 2016-08-26 
22:40 /user/test/profile/city=Orlando

相关问题