数据未加载到Hive中的分区表中

问题描述 投票:3回答:3

我正在尝试为我的表创建分区以更新值。

这是我的样本数据

1,Anne,Admin,50000,A
2,Gokul,Admin,50000,B
3,Janet,Sales,60000,A

我想将Janet's部门更新为B.

因此,为此,我创建了一个以Department作为分区的表。

创建外部表跟踪(EmployeeID Int,FirstName String,Designation String,Salary Int)PARTITIONED BY(Department String)行格式分隔的字段以“,”location“/ user / sreeveni / HIVE”终止;

但在做上述命令的同时。没有数据插入到跟踪表中。

hive>select * from trail;                               
OK
Time taken: 0.193 seconds

hive>desc trail;                                        
OK
employeeid              int                     None                
firstname               string                  None                
designation             string                  None                
salary                  int                     None                
department              string                  None                

# Partition Information      
# col_name              data_type               comment             

department              string                  None   

我做错了吗?

UPDATE

正如建议我尝试将数据插入到我的表中

加载数据在路径'/ user / aibladmin / HIVE'覆盖到表跟踪分区(部门);

但它正在显示

FAILED:SemanticException [错误10096]:动态分区严格模式至少需要一个静态分区列。要关闭它,请设置hive.exec.dynamic.partition.mode = nonstrict

设置qazxsw poi后也没有正常工作。

还有别的事可做。

hadoop mapreduce hive partition
3个回答
15
投票

尝试以下两个属性

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

在为分区表编写insert语句时,请确保在select子句中指定最后一个分区列。


2
投票

您无法直接将数据(Hdfs文件)插入到分区的配置单元表中。首先,您需要创建一个普通表,然后将该表数据插入到分区表中。

SET hive.exec.dynamic.partition = true; SET hive.exec.dynamic.partition.mode = nonstrict; 意味着当你填充hive表时,它必须至少有一个静态分区列。

set hive.exec.dynamic.partition.mode=strict在此模式下,您不需要任何静态分区列。


2
投票

请尝试以下方法:

首先创建表:

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

使用分区名称在hdfs中创建目录:

create external table test23 (EmployeeID Int,FirstName String,Designation String,Salary Int) PARTITIONED BY (Department String) row format delimited fields terminated by "," location '/user/rocky/HIVE';

通过过滤部门等于50000的记录来创建本地文件$ hadoop fs -mkdir /user/rocky/HIVE/department=50000

abc.txt

把它放入HDFS:

$ cat abc.txt 
1,Anne,Admin,50000,A
2,Gokul,Admin,50000,B

现在改变表格:

$ hadoop fs -put /home/yarn/abc.txt /user/rocky/HIVE/department=50000

并检查结果:

ALTER TABLE test23 ADD PARTITION(department=50000);
© www.soinside.com 2019 - 2024. All rights reserved.