将普通列转换为配置单元中的分区列

uyto3xhc  于 2021-06-03  发布在  Hadoop
关注(0)|答案(3)|浏览(292)

我有一张三列的table。现在我需要将其中一列修改为分区列。有没有可能?如果没有,我们如何将分区添加到现有表中。我使用了以下语法:create table t1(eno int,ename string)行格式分隔字段,以'\t'结尾;将数据本地'/..path/'加载到表t1中;alter table t1 add partition(p1='india');
我有错误。。。。。。。。。
有人知道如何将分区添加到现有表中吗。。。。。。?
提前谢谢。

brqmpdu1

brqmpdu11#

我认为没有办法将表的现有列转换为分区。如果您想在一个表中添加一个分区,请使用alter命令。如果您处理的是外部表,那么还需要指定位置字段。我不确定是否可以使用alter命令为托管表添加分区。

rhfm7lfc

rhfm7lfc2#

我不认为这是直接可能的。hive必须完全重新排列和分割hdfs中的文件,因为添加分区将强制使用新的目录结构。
我建议您只需使用所需的模式和分区创建一个新表,然后将第一个表中的所有内容插入第二个表中。

jtoj6r0c

jtoj6r0c3#

不能将分区添加到已创建的表中。但你可以像这样做。创建一个新表并将数据从旧表插入新表。

/*Original table structure*/
CREATE  TABLE original_table(
    c1 string,
    c2 string,
    c3 string)
STORED AS ORC;

/*Partitioned table structure*/
CREATE  TABLE partitioned_table(
    c1 string,
    c2 string)
partitioned by (c3 string)  
STORED AS ORC;

/*load data from original_table to partitioned_table*/
insert into table partitioned_table partition(c3)     select c1,c2,c3 from  original_table;

/*remae original_table to old_table. You can just drop it if you want it*/
ALTER TABLE original_table RENAME TO old_table;

/*rename partitioned_table to original_table*/
ALTER TABLE partitioned_table RENAME TO original_table;

相关问题