Hadoop 配置单元将多个分区的HDFS文件加载到表

Hadoop 配置单元将多个分区的HDFS文件加载到表,hadoop,hive,hdfs,hive-partitions,hiveddl,Hadoop,Hive,Hdfs,Hive Partitions,Hiveddl,我在HDFS中有一些两次分区的文件,其结构如下: /user/hive/warehouse/datascience.db/simulations/datekey=20210506/coeff=0.5/data.parquet /user/hive/warehouse/datascience.db/simulations/datekey=20210506/coeff=0.75/data.parquet /user/hive/warehouse/datascience.db/simulations/

我在HDFS中有一些两次分区的文件,其结构如下:

/user/hive/warehouse/datascience.db/simulations/datekey=20210506/coeff=0.5/data.parquet
/user/hive/warehouse/datascience.db/simulations/datekey=20210506/coeff=0.75/data.parquet
/user/hive/warehouse/datascience.db/simulations/datekey=20210506/coeff=1.0/data.parquet
/user/hive/warehouse/datascience.db/simulations/datekey=20210507/coeff=0.5/data.parquet
/user/hive/warehouse/datascience.db/simulations/datekey=20210507/coeff=0.75/data.parquet
/user/hive/warehouse/datascience.db/simulations/datekey=20210507/coeff=1.0/data.parquet
我想把它们尽可能优雅地放进蜂箱的桌子里。我知道这样的典型解决方案是首先将所有数据加载到一个非分区表中,然后使用前面提到的动态分区将所有数据传输到最终的表中

但是,我的文件在实际数据中没有datekey和coeff值,它只在文件名中,因为这就是它的分区方式。那么,当我将这些值加载到中间表中时,如何跟踪它们呢

一种解决方法是对每个系数值和日期键执行单独的
加载数据inpath
查询。这不需要中间表,但会很麻烦,而且可能不是最优的


有更好的方法吗?

典型的解决方案是在hdfs目录上构建外部分区表:

create external table table_name (
column1 datatype, 
column2 datatype,
...
columnN datatype 
)
partitioned by (datekey int,
                coeff float)
STORED AS PARQUET
LOCATION '/user/hive/warehouse/datascience.db/simulations'
之后,恢复所有分区,此命令将扫描表位置并在配置单元元数据中创建分区:

MSCK REPAIR TABLE table_name;
现在,您可以查询表列和分区列,并对其执行任何操作:按原样使用,或使用insert加载到另一个表中。。选择,等等:

select 
    column1, 
    column2,
    ...
    columnN,
    --partition columns
    datekey,
    coeff
from table_name
where datekey = 20210506
; 

您不能
插入到新选项卡(a、b、零件列)中吗?从旧表中选择x、零件列、y
?假设您的新表是不同分区的。谢谢,这比我以前计划做的要好得多!