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

Is it possible to execute query independently on each partition?

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

执行此操作的唯一方法是创建一个选择特定分区的查询,并在查询之间使用 union all 来合并结果。我不确定您使用的是哪个 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 个阶段。