hive sql

Han Hanju·2021년 10월 10일
0
post-thumbnail
  • hive 테이블을 이용하여 hdfs에 저장된 json파일들을 읽는 방법

1. hive 데이터베이스 생성

CREATE DATABASE IF NOT EXISTS db_nm;

2. hdfs의 json파일을 이용한 테이블 생성

1) external table 만들기

CREATE EXTERNAL TABLE IF NOT EXISTS db_nm.tb_nm ( 
  repotype string, 
  repo string, 
  requser string, 
  tags array<string>
) 
PARTITIONED BY (dt string) 
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
STORED AS TEXTFILE 
LOCATION 'hdfs://name/tmp/log' 
;

2) managed table 만들기

CREATE TABLE IF NOT EXISTS db_nm.tb_nm ( 
  repotype string, 
  repo string, 
  requser string, 
  tags array<string>
) 
PARTITIONED BY (dt string) 
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
STORED AS TEXTFILE 
LOCATION 'hdfs://name/tmp/log' 
;

3. hive 테이블 파티션 등록

  • hdfs경로의 파티션이(dt=20200326)와 같은 경우가 아니므로 직접 파티션과 hdfs 경로 매핑필요.
ALTER TABLE db_nm.tb_nm ADD PARTITION (dt='20200326') LOCATION '/tmp/log/20200326';

Reference

https://heum-story.tistory.com/141

profile
Data Analytics Engineer

0개의 댓글