当 Select 语句中的特定列具有所有双精度值时,为什么 Hive SQL 返回该列的 NULL 值?



我正在使用Hive SQL。 版本为 Hive 1.1.0-cdh5.14.0。 在下面的示例中,sp.close 是一列类型为双精度值的列。 我检查了sp.column,绝对没有空值。 然而,在下面的选择语句中,sp.close 显示所有 NULL 值。 为什么?

select
step1.*,
sp.close
from
step1 left join stockprices2 sp on (
step1.symbol = sp.symbol and
step1.year = sp.year and
step1.startmonth = sp.month and
step1.startday = sp.day and
step1.sector = sp.sector
)
;

最有可能的是,您的left join没有在stockprices2中找到匹配行。在这种情况下,将保留step1中的行,但结果集中将nullstockprices2的所有列。这是数据库发出left join为空的信号的设计方式。

您可以通过将left join追逐到inner join来轻松验证这一点:您应该返回更少的行(如果stockprices2中没有匹配项,则从结果集中删除来自step1的行(,并且sp.close中没有null值。

或者,您可以在select子句中添加left join条件中使用的列之一,并查看它也null

select
st.*,
sp.close,
sp.symbol   -- null too
from step1 st 
left join stockprices2 sp 
on  st.symbol = sp.symbol 
and st.year = sp.year 
and st.startmonth = sp.month 
and st.startday = sp.day 
and st.sector = sp.sector

旁注:连接条件两边的括号是多余的。

最新更新