- hive 는 자바 프로그래밍 기술은 부족하지만 강력한 sql 기술을 가진 분석가가 페이스북의 hdfs 에 저장된 대량의 데이터를 분석할 수 있도록 새발됐다.
17.1 hive 설치
- 일반적으로 하이브는 사용자의 워크스테이션에서 실행되고 , 작성된 sql 쿼리는 일련의 맵리듀스 잡으로 변화돼 하둡 클러스터에 구동된다.
- 하이브는 hdfs 에 저장된 데이터(디렉토리, 파일)에 구조(스키마)를 입히는 방식으로 데이터를 테이블로 구조화시킨다.
- 테이블 스키마와 같은 메타데이터는 메타스토어라는 데이터베이스에 저장된다.
- (하이브는 모든 버전의 하둡과호환함)
# Download a release, and unpack the tarball in a suitable place on your workstation:
% tar xzf apache-hive-x.y.z-bin.tar.gz
# It’s handy to put Hive on your path to make it easy to launch:
% export HIVE_HOME=~/sw/apache-hive-x.y.z-bin
% export PATH=$PATH:$HIVE_HOME/bin
# Now type hive to launch the Hive shell:
% hive
hive>
17.1.1. hive shell
- hive shell 은 hiveql 명령어로 하이브와 상호작용
- hql 은 mysql 에 큰 영향을 받았다.
- 명령어는
;
로 끝나야함.
- 대소문자 구문 안함
hive> SHOW TABLES;
OK
Time taken: 0.473 seconds
- 로컬에 설치했을 경우, 사용자가 hive를 실행한 위치에
metastore_db
라는 디렉토리를 만들어 필요한 파일을 저장한다.
% hive -f script.q
# f -> file
% hive -e 'SELECT * FROM dummy'
OK
X
Time taken: 1.22 seconds, Fetched: 1 row(s)
# e -> 명령행에 직접 입력
% hive -S -e 'SELECT * FROM dummy'
X
# s : 불필요한 메시지 출력을 막아 출력결과만 보게
# 그 밖에 다른 유용 특성으로 명령어 앞에 !를 붙여 호스트 운영체제의 명령어를 실행하는 기능ㅇ과
# dfs 명령어로 하둡 파일 시스템을 조작하는 기능이 있다.
17.2. 예제