为什么 Hive SQL 在 Select 语句中的特定列具有所有双精度值时返回 NULL 值?
Why Hive SQL returning NULL values for a particular column in Select statement when that column has all double values?
我正在使用 Hive SQL。版本为 Hive 1.1.0-cdh5.14.0。在我下面的示例中,sp.close 是一个具有双精度值类型的列。我检查了 sp.column 并且绝对没有 NULL 值。然而,在下面的 select 语句中,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
的行将被保留,但来自 stockprices2
的所有列在结果集中将是 null
。这是设计使然,数据库发出 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
旁注:连接条件两边的括号是多余的。
我正在使用 Hive SQL。版本为 Hive 1.1.0-cdh5.14.0。在我下面的示例中,sp.close 是一个具有双精度值类型的列。我检查了 sp.column 并且绝对没有 NULL 值。然而,在下面的 select 语句中,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
的行将被保留,但来自 stockprices2
的所有列在结果集中将是 null
。这是设计使然,数据库发出 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
旁注:连接条件两边的括号是多余的。