如何将数据从hdfs表导入到配置单元中的嵌套分区表中?

jei2mxaa  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(267)

我在Hive里做了一个嵌套的分区表。但我不知道如何在表中插入数据。
我尝试了插入覆盖表方法。
在Hive里,

create external table accounts_nested(
first_name string, last_name string, zipcode string)
partitioned by (state string, areacode string) 
row format delimited 
fields terminated by ',' 
location '/loudacre/accounts_nested';

然后,

insert overwrite table accounts_nested(
partition(areacode)
select first_name, last_name, zipcode, state, areacode from accounts;

我在终端上看不到任何错误,但我看不到插入的数据。
我想看看表中的数据。

42fyovps

42fyovps1#

可以使用dinamic分区设置下一个参数。

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

下面是一个代码示例:

create table temp.accounts           (                                                                                                                                                                                     
first_name                  string
,last_name                  string
,zipcode                  string
)
partitioned by (areacode string)
stored as parquet location '/temp.db/accounts' tblproperties("parquet.compression=SNAPPY")
;

insert into temp.accounts partition(areacode='0') values
('David','David','00')
,('Ellen', 'Ellen','00')
,('David','David','00')
,('David', 'David','00');

create external table temp.accounts_nested           (                                                                                                                                                                                     
first_name                  string
,last_name                  string
,zipcode                  string
)
partitioned by (areacode string)
stored as parquet location '/temp.db/accounts_nested' tblproperties("parquet.compression=SNAPPY")
;

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

insert overwrite table temp.accounts_nested 
partition(areacode)
select first_name, last_name, zipcode, areacode from temp.accounts;

输出:

select * from temp.accounts_nested;
+-----------------------------+----------------------------+--------------------------+---------------------------+--+
| accounts_nested.first_name  | accounts_nested.last_name  | accounts_nested.zipcode  | accounts_nested.areacode  |
+-----------------------------+----------------------------+--------------------------+---------------------------+--+
| David                       | David                      | 00                       | 0                         |
| Ellen                       | Ellen                      | 00                       | 0                         |
| David                       | David                      | 00                       | 0                         |
| David                       | David                      | 00                       | 0                         |
+-----------------------------+----------------------------+--------------------------+---------------------------+--+

相关问题