Bigquery Error
No matching signature for function IF for argument types
: if 사용하여 항목 선택하고자 할 때, 항목별 data type을 엄격하게 체크하기 때문에 발생
select if(bigtt <> '', ‘널체크불가능', ‘널체크가능') as ttt
from ( select null as bigtt ) aa
No matching signature for operator != for argument types: INT64, STRING. Supported signatures: ANY != ANY at [2:11]
No matching signature for operator != for argument types: INT64, STRING. Supported signatures: ANY != ANY at [2:11]
각 세션에서 data type이 달라 에러가 발생한다.
-- 아래와 같이 하거나
select if(bigtt is not null, ‘널체크불가능', ‘널체크가능') as ttt
from ( select null as bigtt ) aa
-- hive에서는 가능
select if(bigtt <> '', '널체크불가능', '널체크가능') as ttt
from ( select null as bigtt ) aa
마찬가지로,
select count(distinct if(mid is not null, if(cnt > 0, uuid, null), 0)) as uuid_uv
from (
select '1029382' as mid, 10 as cnt, '21093823k1230912213' as uuid
union all
select '1029382' as mid, 12 as cnt, '21093823k1230912213' as uuid
) abc
No matching signature for function IF for argument types: BOOL, STRING, INT64. Supported signature: IF(BOOL, ANY, ANY) at [2:23]
hive에서는 동작하는 쿼리이지만 bigquery if 에서는 string과 null을 취사선택하도록 할 수 없다
그럼 어떻게?? CASE로 처리
select count(distinct CASE WHEN mid is not null THEN CASE WHEN cnt>0 THEN uuid END ELSE null END) as uuid_uv
from (
select '1029382' as mid, 10 as cnt, '21093823k1230912213' as uuid
union all
select '1029382' as mid, 12 as cnt, '21093823k1230912213' as uuid
) abc