【发布时间】:2017-11-10 08:10:47
【问题描述】:
我正在尝试连接 7 个表并将连接的数据插入到一个大的连接表中,为此我使用下面的查询
INSERT OVERWRITE TABLE databaseName.joinTab PARTITION (tran_date)
SELECT <180 cols across all 7 tables>
FROM databaseName.table1 tab1
LEFT OUTER JOIN databaseName.table2 tab2 ON (tab1.id = tab2.id and
tab1.tran_date='20171030' and tab2.tran_date='20171030')
LEFT OUTER JOIN databaseName.table3 tab3 ON (tab1.id = tab3.id and
tab1.tran_date='20171030' and tab3.tran_date='20171030')
LEFT OUTER JOIN databaseName.table4 tab4 ON (tab1.id = tab4.id and
tab1.tran_date='20171030' and tab4.tran_date='20171030')
LEFT OUTER JOIN databaseName.table5 tab5 ON (tab1.id = tab5.id and
tab1.tran_date='20171030' and tab5.tran_date='20171030')
LEFT OUTER JOIN databaseName.table6 tab6 ON (tab1.id = tab6.id and
tab1.tran_date='20171030' and tab6.tran_date='20171030')
LEFT OUTER JOIN databaseName.table7 tab7 ON (tab1.id = tab7.id and
tab1.tran_date='20171030' and tab7.tran_date='20171030')
WHERE (tab1.tran_date='20171030');
tran_date 是所有这些表的分区列,我有 where 子句以及 ON 语句中的条件的原因是我发现启动的 tez 作业将对 table1 进行全表扫描如果我没有。
所以我的问题是,如果我在 tran_date=20171030 上从 table1 进行计数(*),那么我得到 11845917 作为结果
如果我对同一个分区 tran_date=20171030 从新加入的表 (joinTab) 进行计数 (*),我只会得到 97609 的结果,这是一个非常大的差异,因为我使用的是我曾想过的左外连接它应该将所有数据从 table1 移动到连接表中,并为不在其他表中的任何内容填充空值。我应该提到 joinTab 中的 tran_date 是从 table1 数据加载时派生的
这里有什么看起来不对的地方吗?
感谢您的帮助
丹
【问题讨论】:
标签: sql hadoop join hive hiveql