简体   繁体   English

如何在不移动数据的情况下从另一个具有不同分区的配置单元表创建配置单元表?

[英]How to create a hive table from another hive table with different partition without moving data?

I have a table database1.table1 我有一个表database1.table1

Table 'database1.table1' has 2 columns and one partition column: columnA, columnB partitioned by columnC 表'database1.table1'具有2列和一个分区列:columnA,columnB由columnC分区

I need to create a table 'database2.table2' with no partition but with two columns columnA, columnB. 我需要创建一个没有分区但有两列columnA,columnB的表“ database2.table2”。 I need to COPY the data from database1.table1 into database2.table2 (without deleting any data in database1.table1) 我需要将database1.table1中的数据复制到database2.table2中(而不删除database1.table1中的任何数据)

I tried the following but the data gets moved. 我尝试了以下操作,但是数据被移动了。 I need to just copy the data 我只需要复制数据

CREATE TABLE DATABASE2.TABLE2 
SELECT COLUMNA, COLUMNB
FROM DATABASE1.TABLE1

Note: I need the table with actual data and I can not create an EXTERNAL table. 注意:我需要包含实际数据的表,并且无法创建EXTERNAL表。

You should be able to copy the data almost the way you were saying. 您应该能够几乎按照您说的方式复制数据。 Just add 'AS'. 只需添加“ AS”即可。 See the CREATE AS SELECT documentation . 请参阅CREATE AS SELECT文档 You're saying that the data is moved, but that can't be. 您说的是数据已移动,但事实并非如此。 CREATE AS SELECT will trigger a map reduce job. CREATE AS SELECT将触发地图缩小作业。 Notice in the docs that you can also change the data format, use a different serde, and your own partitioning (or no partitioning, like you're asking). 请注意,在文档中,您还可以更改数据格式,使用不同的Serde以及自己的分区(或不分区,就像您要的那样)。

USE database2;
CREATE TABLE table2 
  AS SELECT columna,columnb 
  FROM database1.table1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM