Cloudera CDH/CDP 및 Hadoop EcoSystem, Semantic IoT등의 개발/운영 기술을 정리합니다. gooper@gooper.com로 문의 주세요.
sqoop에서 mapper를 2이상으로 설정하기 위한 split-by컬럼을 찾을때 유용하게 활용할 수 있는 쿼리
(abctable에서 part_ym='201908'인 데이터를 가지고 test_col이라는 컬럼의 값을 이용하여 10등분하고 그 개수를 확인하는 impala sql임, -1은 마지막 값에 속하는 개수를 의미함)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | select tt, count (*) from { select case when bb.lapse1 <= cast (substr(aa.test_col, 5,4) as int ) and case (substr(aa.test_col, 5,4) as int ) < bb.lapse2 then t when t=10 and bb.lapse2 = cast (substr(aa.test_col, 5,4) as int ) then -1 end tt from ( select * from dw.abctable where part_ym= '201908' aa, ( select min_val, max_vl, t, max_val*((t-1)/10) as lapse1, max_val*((t+0)/10) as lapse2 from ( select min ( cast (substr(test_col, 5,4) as int )) as min_val, max ( cast (substr(test_col, 5,4) as int )) as max_val from dw.abctable where part_ym= '201908' ) a, ( select cast (t as int ) as t from copy_t where t in ( '01' , '02' , '03' , '04' , '05' , '06' , '07' , '08' , '09' , '10' )) b ) bb } kk where kk.tt is not null group by kk.tt order by 1; |