问题描述:hive原始表old,二级分区分别是month,day,现在要求将指定分区下的所有数据导入一张新表new,new复制old表结构
create table new like old;
导入数据SQL语句
insert overwrite table new partition(month=‘10’,day=‘01’) select * from old where month='10' and day='01';
异常一:FAILED: SemanticException [Error 10044]: Line 1:23 Cannot insert into target table because column number/types are different ‘‘01’’: Table insclause-0 has 3 columns, but query has 5 columns.
错误原因:导入分区表时,只要写明分区字段名就行,不要写具体字段值partition(month=‘10’,day=‘01’) 错误
正确语句:
insert overwrite table new partition(month,day) select * from old where month='10' and day='01';
异常二:FAILED: SemanticException 1:23 Dynamic partition is disabled. Either enable it by setting hive.exec.dynamic.partition=true or specify partition column values. Error encountered near token ‘day’
错误原因:未开启动态分区
set hive.exec.dynamic.partition=true;//开启动态分区
异常三:FAILED: SemanticException [Error 10096]: Dynamic partition strict mode requires at least one static partition column. To turn this off set hive.exec.dynamic.partition.mode=nonstrict
错误原因:未关闭严格模式
set hive.exec.dynamic.partition.mode=nonstrict;//设置为非严格模式
备注:严格模式
Hive提供了一个严格模式,可以防止用户执行那些可能产生意想不到的不好的效果的查询。
如:
- 分区表的查询没有使用分区字段来限制。
- 使用了笛卡尔积
- order by 的时候没有使用limit