我有一个Hive表,它是通过联接来自多个表的数据而创建的。此数据位于一个具有多个文件(“ 0001_1”,“ 0001_2”等)的文件夹中。我需要基于此表中的日期字段创建一个分区表pt_dt(通过更改此表或创建一个新表)。有没有办法做到这一点?
我尝试创建一个新表并将其插入(下图),该表不起作用
create external table table2 (acct_id bigint, eval_dt string)
partitioned by (pt_dt string);
insert into table2
partition (pt_dt)
select acct_id, eval_dt, pt_dt
from jmx948_variable_summary;
Run Code Online (Sandbox Code Playgroud)
这引发错误
“失败:执行错误,从org.apache.hadoop.hive.ql.exec.mr.MapRedTask返回Map 2,启动MapReduce作业:Stage-Stage-1:Map:189累积CPU:401.68 sec HDFS读取:0 HDFS写入: 0 FAIL MapReduce花费的总CPU时间:6分41秒680毫秒”
经过一番尝试和错误后能够弄清楚。
在Hive中启用动态分区:
SET hive.exec.dynamic.partition = true;
SET hive.exec.dynamic.partition.mode = nonstrict;
Run Code Online (Sandbox Code Playgroud)
为分区表创建模式:
CREATE TABLE table1 (id STRING, info STRING)
PARTITIONED BY ( tdate STRING);
Run Code Online (Sandbox Code Playgroud)
插入分区表:
FROM table2 t2
INSERT OVERWRITE TABLE table1 PARTITION(tdate)
SELECT t2.id, t2.info, t2.tdate
DISTRIBUTE BY tdate;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7521 次 |
| 最近记录: |