Study

hive query ์—์„œ hivevar ์‚ฌ์šฉํ•˜๊ธฐ

whistory 2023. 4. 7. 13:44
๋ฐ˜์‘ํ˜•

 

 

 

 

๐Ÿ’ก hive query ์—์„œ ๋ณ€์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„,๋ณ€์ˆ˜๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณธ๋‹ค.

 

 

hive query ์—์„œ

์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ hivevar๋ฅผ ์„ ์–ธํ•ด์ค€๋‹ค.

SET hivevar:from_month = SOMETHING;

 

 

๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ , ์ƒ์„ฑํ•œ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉ๋Š” query๋ฅผ ์ž‘์„ฑํ•ด๋ณด๋„๋ก ํ•œ๋‹ค.

 

 

 

 

 

๋ณ€์ˆ˜๋ฅผ string ๊ฐ’์ด ์•„๋‹Œ,

์ฟผ๋ฆฌ๋ฌธ์œผ๋กœ ์„ ์–ธ ํ•  ์ˆ˜ ๋„ ์žˆ๋‹ค.

SET hivevar:qs = date_format(add_months(trunc("${hivevar:from}", "MM) 
                        , CASE WHEN date_format("${hivevar:from}", "dd') < 17 THEN -2 
                                ELSE -1 
                                END)
                    , 'yyyy-MM');

 

 

 

 

 

 

 

oozie workflow์—์„œ 'from' ๊ณผ 'to'๋ผ๋Š” ๋‚ ์งœ ๋ณ€์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›๊ณ .

์ด ๋ณ€์ˆ˜๋“ค์„ ํ™œ์šฉํ•ด๋ณธ๋‹ค.

 

 

 

SET hivevar:from_month = date_format("${hivevar:from}", 'YYYY-MM');
SET hivevar:to_month = date_format("${hivevar: to}", "YYYY-MM');

SET hivevar:qs = date_format(add_months(trunc("${hivevar:from}", "MM) 
                , CASE WHEN date_format("${hivevar:from}", "dd') < 17 THEN -2 
                        ELSE -1 
                        END)
            , 'yyyy-MM');

SELECT $(hivevar:from_month) AS from month
			, $(hivevar:to_month) AS to_month
			, "${hivevar:from)" AS from_conditon
			, "${hivevar:to)" AS to_conditon
			, $(hivevar:qs) AS qs

 

๋ฐ˜์‘ํ˜•