gpt4 book ai didi

sql - UNION ALL 不会在 Hive 中生成任何数据

转载 作者:可可西里 更新时间:2023-11-01 15:45:51 26 4
gpt4 key购买 nike

我正在尝试对具有相同 DDL 结构的三个不同表执行 UNION ALL,但最终输出生成零行。我不知道底层执行中发生了什么。有人可以分享您对此的看法吗?我的示例 Hive SQL 如下所示。谢谢。

SET hive.execution.engine=tez;
SET hive.exec.dynamic.partition.mode=nonstrict;
SET hive.qubole.cleanup.partial.data.on.failure=true;
SET hive.tez.container.size=8192;
SET tez.task.resource.memory.mb=8192;
SET tez.task.resource.cpu.vcores=2;
SET hive.mapred.mode=nonstrict;
SET hive.qubole.dynpart.use.prefix=true;
SET hive.vectorized.execution.enabled=true;
SET hive.vectorized.execution.reduce.enabled =true;
SET hive.cbo.enable=true;
SET hive.compute.query.using.stats=true;
SET hive.stats.fetch.column.stats=true;
SET hive.stats.fetch.partition.stats=true;
SET mapred.reduce.tasks = -1;
SET hive.auto.convert.join.noconditionaltask.size=2730;
SET hive.auto.convert.join=true;
SET hive.auto.convert.join.noconditionaltask=true;
SET hive.auto.convert.join.noconditionaltask.size=405306368;
SET hive.compute.query.using.stats=true;
SET hive.stats.fetch.column.stats=true;
SET hive.stats.fetch.partition.stats=true;
SET mapreduce.job.reduce.slowstart.completedmaps=0.8;


CREATE TABLE IF NOT EXISTS X STORED AS PARQUET AS
SELECT a,
b,
c
FROM A
UNION ALL
SELECT a,
b,
c
FROM B
UNION ALL
SELECT a,
b,
c
FROM C;

如果我尝试在 Presto 上运行以下查询,它会显示有数据。

SELECT COUNT(1) FROM 
(
SELECT a,
b,
c
FROM A
UNION ALL
SELECT a,
b,
c
FROM B
UNION ALL
SELECT a,
b,
c
FROM C
)Z;

最佳答案

UNION ALL 在 Tez 上运行时并行运行并在表位置创建额外的子目录(检查表位置内的内容)。尝试在读取表之前添加这些配置设置以允许 Hive 读取子目录:

set hive.mapred.supports.subdirectories=true; 
set mapred.input.dir.recursive=true;

您的查询非常简单并且在映射器上运行 - 只有每个子查询写入它自己的子目录并且不会干扰另一个子目录。

或者您可以通过在末尾添加distribute byorder by(运行速度较慢)来强制执行额外的reducer 阶段,改为运行UNION UNION ALL,在 union 等之后应用过滤器 - 它将在没有子目录的表文件夹中创建文件:

CREATE  TABLE IF NOT EXISTS X STORED AS PARQUET AS 
select * from
(
SELECT a,
b,
c
FROM A
UNION ALL
SELECT a,
b,
c
FROM B
UNION ALL
SELECT a,
b,
c
FROM C
)s distribute by a; --this will force reducer step

关于sql - UNION ALL 不会在 Hive 中生成任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54996941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com