반응형

bigquery는 nvl이 없음(정확하게는 구버전은 있고 일반적으로 사용하는 신버전은 없다)

 

대체 가능 함수

1. IFNULL

    select IFNULL(null, '0');

!! NULLIF와 다름에 유의할 것(NULLIF는 첫번째 expr와 두번째 expr가 같을 경우 null을 반환하고, 아닐 경우 첫번째 expr를 반환)

 

2. COALESCE

    select COALESCE(null, '0');

 

이걸 적어두는 이유는.. ifnull에다 nullif 써놓고 왜 계속 null이 찍히나 ..한참 시간을.. ㅠ

반응형

'Ecosystem > bigquery' 카테고리의 다른 글

No matching signature for function IF for argument types  (0) 2019.12.16
반응형

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

 

반응형

'Ecosystem > bigquery' 카테고리의 다른 글

bigquery nvl 대체  (0) 2020.11.08

+ Recent posts