我有一个带有2 columns.Employee ID和Salary的Hive Table。
数据如下所示。
Employee ID Salary
1 10000.08
2 20078.67
3 20056.45
4 30000.76
5 10045.14
6 43567.76
Run Code Online (Sandbox Code Playgroud)
我想基于薪水列创建分区,例如薪水范围为10000到20000、20001到30000的分区。
我该如何做到这一点。
Hive不支持范围分区,但是您可以在数据加载期间计算范围。
创建按薪金范围划分的表:
create table your_table
(
employee_id bigint,
salary double
)
partitioned by (salary_range bigint)
Run Code Online (Sandbox Code Playgroud)插入用例进行工资范围计算:
insert overwrite table your_table partition (salary_range)
select employee_id, salary,
case
when salary between 10000 and 20000 then 20000
when salary between 20001 and 30000 then 30000
...
else ...
end as salary_range
from some_table;
Run Code Online (Sandbox Code Playgroud)