hive中的笛卡尔积

Hive本身是不支持笛卡尔积的,不能用select T1.*, T2.* from table_1, table_2这种语法。但有时候确实需要用到笛卡尔积的时候,可以用下面的语法来实现同样的效果:

select T1.*, T2.* from

(select * from table1) T1

join

(select * from table2) T2

on 1=1;

其中on 1=1是可选的,注意在Hive的Strict模式下不能用这种语法,需要先用set hive.mapred.mode=nonstrict;设为非strict模式就可以用了。

猜你喜欢

转载自blog.csdn.net/yisun123456/article/details/82114662