是否可以在每个分区上独立执行查询?

时间:2017-10-04 12:06:08

标签: sql hive hiveql

我有一个非常复杂的查询,需要花费很多时间才能完成。但是,表有分区,实际上如果在每个分区上独立执行此查询,结果都可以。这种方式排序将限于较小的数据部分,这对我来说很好。是否可以在每个分区上独立执行此类查询?

1 个答案:

答案 0 :(得分:1)

执行此操作的唯一方法是创建一个选择特定分区的查询,并在查询之间使用联合来合并结果。我不确定您使用的Hive版本,但请确保设置以下属性

set hive.exec.parallel=true;

查询示例

select sum(a) from table1 where partition1='a'
union all
select sum(a) from table1 where partition1='b'
union all
select sum(a) from table1 where partition1='c';

您可以并行启动3个独立阶段,并合并1个阶段以巩固结果。您可以使用

进行验证
explain
select sum(a) from table1 where partition1='a'
union all
select sum(a) from table1 where partition1='b'
union all
select sum(a) from table1 where partition1='c';

你应该看到平行的3个阶段和1个阶段,取决于其他3个阶段。