AND - is a boolean operator. It seems like cookie
is a string, not boolean. try to replace count(l.cookie and c.cookie)
with this: count(case when l.cookie is not null and c.cookie is not null then 1 else NULL end) as common
Count rows with non-NULL in two columns
Pergunta
I am trying to compare two sets in SQL:
create table my_counts
as select count(*) as total,
count(c.cookie) as first,
count(l.cookie) as second,
count(l.cookie and c.cookie) as common
from (select distinct s.cookie from ...) c
full outer join
(select distinct s.cookie from ...) l
on c.cookie = l.cookie;
select * from my_counts;
However, the above fails with this error:
FAILED:
ClassCastException
org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector
cannot be cast toorg.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector
Of course (assuming the SQL statement above does what I think it should do), I should have total + common = first + second
, so the common
column is not strictly necessary, but I still wonder if there is a way to count the rows where both columns are non-NULL
.
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow