【问题标题】:Insert into hive partitioned table SemanticException插入 hive 分区表 SemanticException
【发布时间】:2018-01-03 13:35:41
【问题描述】:

首先我创建一个 hive 分区表:

hive> create table partition_table
    > (sid int ,sname string ,age int)            
    > partitioned by (sex string)     
    > row format delimited fields terminated by',';  
OK
Time taken: 1.232 seconds

表格描述如下:

 hive> desc partition_table;
    OK
    sid                     int                                         
    sname                   string                                      
    age                     int                                         
    sex                     string                                      

# Partition Information      
# col_name              data_type               comment             

sex                     string                                      
Time taken: 0.34 seconds, Fetched: 9 row(s)

然后我在这个表中插入了一些数据,但它不起作用。

hive> insert into table partition_table partition(sex='M')select sno ,sname ,age from student1 where sex ='M';
FAILED: SemanticException [Error 10006]: Line 1:44 Partition not found ''M''

为了避免这种情况,我编写了以下命令,然后执行了我的插入命令,即使这样我还是反复收到同样的错误。

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

【问题讨论】:

  • 您能否将select sno ,sname ,age from student1 where sex ='M' 输出添加到问题中。查询没有问题。
  • 当然..分区列一定要英文吗

标签: hadoop hive


【解决方案1】:

加载前添加分区:

ALTER TABLE partition_table ADD PARTITION( sex= 'M' );
insert into table partition_table partition(sex='M') select sno ,sname ,age from student1 where sex ='M';

或尝试动态分区:

set hive.exec.dynamic.partition=true;
INSERT OVERWRITE TABLE partition_table PARTITION (sex)
SELECT sid, sname, age, sex
FROM student1;

【讨论】:

  • 不需要添加分区。查询会自动完成。
  • 你可以看到他的错误说它没有找到分区'M'。在我的第二个解决方案中,您可以看到我推荐的动态分区。你在第四行停止阅读了吗?
  • 您的回答非常有用,但是当我尝试 `ALTER TABLE partition_table ADD PARTITION(sex='xxx'); ` -- 它导致了一个新错误FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.) 但我已经设置了hive-site.xml javax.jdo.option.ConnectionURLjdbc:mysql://djt01:3306/ hive?characterEncoding=UTF-8JDBC Metastore 的 JDBC 连接字符串
  • 我搜索这个错误可能是字符设置问题
  • 是否分区列必须是英文的。我使用其他语言
猜你喜欢
  • 2014-12-05
  • 2015-01-09
  • 2015-09-13
  • 1970-01-01
  • 2019-02-16
  • 2018-09-07
  • 2020-02-10
  • 1970-01-01
  • 2014-03-27
相关资源
最近更新 更多