๐Ÿ’ปTech/๐ŸHIVE

[Hive] sequence ์ปฌ๋Ÿผ ์ƒ์„ฑ ๋ฐฉ๋ฒ•

_viper_ 2021. 4. 28. 16:52
๋ฐ˜์‘ํ˜•

๐Ÿ™†‍โ™‚๏ธ ROW_NUMBER() OVER() ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ seq ๋ฒˆํ˜ธ๋ฅผ ์ €์žฅ

## ๊ธฐ์กด ํ…Œ์ด๋ธ”์—์„œ seq ์ปฌ๋Ÿผ์„ ์ถ”๊ฐ€ํ•œ ํ…Œ์ด๋ธ” ์ƒ์„ฑ
CREATE TABLE new_table(
  seq int,
  code string,
  description string,
  total_emp int,
  salary int
)
STORE AS parquet;

## ๊ธฐ์กด ํ…Œ์ด๋ธ”์— ROW_NUMBER() OVER() ํ•ฉ์ˆ˜ ์‚ฌ์šฉํ•ด์„œ seq ์ปฌ๋Ÿผ ์ถ”๊ฐ€ํ•œ ๋ฐ์ดํ„ฐ insert
insert overwrite table new_table
select * from (
select ROW_NUMBER() OVER() as RNUM, *
  from old_table) a where a.RNUM <= 100000000;