为什么配置单元SQL在Select语句中为特定列返回空值,而该列具有所有双精度值?
我正在使用配置单元SQL。版本为Hive 1.1.0-cdh5.14.0。在下面的示例中,sp.close是一个类型为double value的列。我检查了sp.column,绝对没有空值。然而,在下面的select语句中,sp.close显示所有空值。为什么?为什么配置单元SQL在Select语句中为特定列返回空值,而该列具有所有双精度值?,sql,join,hive,left-join,hiveql,Sql,Join,Hive,Left Join,Hiveql,我正在使用配置单元SQL。版本为Hive 1.1.0-cdh5.14.0。在下面的示例中,sp.close是一个类型为double value的列。我检查了sp.column,绝对没有空值。然而,在下面的select语句中,sp.close显示所有空值。为什么? select step1.*, sp.close from step1 left join stockprices2 sp on ( step1.symbol = sp.symbol and
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
)
;
最有可能的是,您的
左联接
在股票价格2
中未找到匹配行。在这种情况下,step1
中的行将被保留,但stockprices2
中的所有列将在结果集中null
。这是通过设计数据库如何发出信号,表明左连接
为空
只需将左联接更改为内部联接即可轻松验证:返回的行数应较少(如果股价2
中没有匹配项,则步骤1
中的行将从结果集中删除),并且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
旁注:连接条件周围的括号是多余的。就是这样。回想起来似乎很明显。谢谢