我正在使用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
中的行,但结果集中将null
stockprices2
的所有列。这是数据库发出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
旁注:连接条件两边的括号是多余的。