Sql 如何使用单行表中的列作为标量?

Sql 如何使用单行表中的列作为标量?,sql,hive,Sql,Hive,假设我有一个表tab1,其中只有一行和更大的表big1和big2。 如何使用tab1中的列(包含单个数字)作为标量,例如 select a.foo * tab1.bar - b.quux from big1 a join big2 b by big1.id = big2.id 这有点过分了,但是您可以使用Brickhouse()中的distributed_mapUDF创建一个只有一个键的映射 insert overwrite directory 'mytab1' select bar, 'va

假设我有一个表
tab1
,其中只有一行和更大的表
big1
big2
。 如何使用
tab1
中的列(包含单个数字)作为标量,例如

select a.foo * tab1.bar - b.quux
from big1 a join big2 b by big1.id = big2.id

这有点过分了,但是您可以使用Brickhouse()中的
distributed_map
UDF创建一个只有一个键的映射

insert overwrite directory 'mytab1'
select bar, 'value' from tab1;

add file mytab1;

select a.foo * array_index( map_keys( distributed_map( 'mytab1' ) ),0 ) - b.quux
from big1 a join big2 b on ( big1.id = big2.id )

再做一次加入。只有一排,所以不贵:

select a.foo * tab1.bar - b.quux
from big1 a join big2 b by big1.id = big2.id join tab1;