hive - 如何将数据从 hdfs 表导入 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;
我在终端上看不到任何错误,但看不到我插入的数据。
我想查看accounts_nested 表中的数据。
解决方案
您可以使用动态分区设置下一个参数。
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 |
+-----------------------------+----------------------------+--------------------------+---------------------------+--+
推荐阅读
- ssl - RabbitMQ - Tls 连接 - Golang
- c# - 如何在 C# 中使用搜索逻辑?
- php - 如何根据数据库结果将多个 PHP 复选框设置为选中?
- visual-studio - 在 Visual Studio 2017 中,如何/在哪里配置解决方案资源管理器的解决方案和文件夹视图?
- java - Spark 无法按包含文件夹路径的字符串进行过滤
- cucumber - Gherkin 场景、可重用步骤方法或特定方法
- android - 搜索 Android RecyclerView
- python-3.x - 删除文件夹中除最新的特定文件之外的所有文件
- android - Microsoft Azure 主机名不匹配
- kubernetes - 在唯一节点上部署 Kubernetes pod