레이블이 하둡인 게시물을 표시합니다. 모든 게시물 표시
레이블이 하둡인 게시물을 표시합니다. 모든 게시물 표시

2016년 11월 7일 월요일

sqlite3 to hdfs with hive

sqlite3 에서 사용하던 이력 데이터의 용량이 너무 커져서 하둡 (hive)으로 옮기는 과정을 다룬다.
hive 저장 포맷에 대한 간략한 비교도 포함한다.

목차

  • sqlite3 to hdfs ( hadoop file system )
  • hdfs to hive
  • performance as hive format


sqlite3 에서 hdfs 로 파일 저장하기

sqlite3 -csv big.db “select * from big;” | hadoop fs -put - /user/me/big.csv

**
결과를 local 에 csv 로 저장 할 공간이 없어서, pipe 형식으로 하둡으로 바로 저장했다.
질의 결과를 표준 출력 ( stdout ) 으로 보낼 수 있다면 응용 될 수 있는 방법이다.

hdfs 에서 hive 로 로딩 하기

hortonworks 의 amberi 도구를 사용하면, Hive View 를 만들어서 Upload Table 메뉴를 이용한다.
미리보기 모드에서 파일 포멧, 테이블/컬럼 이름 등을 지정하면 심플하다.

sql 기반의 명령어는 다음과 같다.
테이블 스키마를 먼저 생성하고, csv 파일을 로딩한다.
CREATE TABLE big_text (Column01 int, Column02 string…) STORED AS TEXT;
LOAD DATA INPATH ‘/user/me/big.csv’ [OVERWRITE] INTO TABLE big_text;

다른 형태의 포맷으로 테이블을 만드는 과정이다.
CREATE TABLE big_orc STORED AS ORC AS SELECT * FROM big_text;

**
HIVE는 다양한 포맷을 지원한다.
sequence, text, orc, rc, parquet ..
성능 관점에서 보면 질의 형태에 따라 row 와 column 기반의 포맷에 주의한다.

특정 컬럼  filter에 있어서 text와 orc 포맷 테이블의 질의하기
>> column 기반의 orc에 이점이 있다.

hive> select count(*) from big_orc where sdate = '20160104';
Query ID = root_20161107130507_53898e98-2f58-4ca4-a4c9-ca03a527c8de
Total jobs = 1
Launching Job 1 out of 1


Status: Running (Executing on YARN cluster with App id application_1478242837204_0017)

--------------------------------------------------------------------------------
        VERTICES      STATUS  TOTAL  COMPLETED  RUNNING  PENDING  FAILED  KILLED
--------------------------------------------------------------------------------
Map 1 ..........   SUCCEEDED     20         20        0        0       0       0
Reducer 2 ......   SUCCEEDED      1          1        0        0       0       0
--------------------------------------------------------------------------------
VERTICES: 02/02  [==========================>>] 100%  ELAPSED TIME: 9.08 s  
--------------------------------------------------------------------------------
OK
673374
Time taken: 9.762 seconds, Fetched: 1 row(s)
hive> select count(*) from big_text where sdate = '20160104';
Query ID = root_20161107130524_c2dcdccb-63c1-4502-a305-6a681fa1ea9e
Total jobs = 1
Launching Job 1 out of 1


Status: Running (Executing on YARN cluster with App id application_1478242837204_0017)

--------------------------------------------------------------------------------
        VERTICES      STATUS  TOTAL  COMPLETED  RUNNING  PENDING  FAILED  KILLED
--------------------------------------------------------------------------------
Map 1 ..........   SUCCEEDED     20         20        0        0       0       0
Reducer 2 ......   SUCCEEDED      1          1        0        0       0       0
--------------------------------------------------------------------------------
VERTICES: 02/02  [==========================>>] 100%  ELAPSED TIME: 38.58 s  
--------------------------------------------------------------------------------
OK
673374
Time taken: 39.234 seconds, Fetched: 1 row(s)

참고


hive architecture figure - referred to apache hive homepage


2016년 11월 2일 수요일

hortonworks 하둡 구성하기

호튼에서는
가볍게 기능적인 부분을 확인 할 수 있는 sandbox와
실제 하둡 구성을 도와주고 관리하는 ambari 기반을 제공한다.

두 가지를 구성 할 때, 주의 할 내용들을 요약한다.

  • HDP 2.5 on hortonworks sandbox
  • HDP 2.5 with Ambari 2.4

HDP 2.5 on hortonworks sandbox

sandbox는 기본 8GB 메모리를 요구한다.
hue는 기본 패키지에 없어서 추가로 설치했다.

**
hue 접속 에러 발생 시에 대응 방안이다.

가. 로그 폴더 권한 문제가 발생했다.

/var/log/hue 에 hue 소유자 권한을 준다.
> chown -R hue /var/log/hue

나. django.db 접속 관련 예외가 발생했다.

db를 재생성 한다.

테스트 db를 새롭게 생성한다.
> /usr/lib/hue/build/env/bin/hue testserver
서비스 db를 덮어쓰기 한다.
> cp /usr/lib/hue/desktop/desktop-test.db /var/lib/hue/desktop.db
hue 서비스를 재시작 한다.
> service hue restart


HDP 2.5 with Ambari 2.4

1. 전체 노드에 사전 작업을 한다.

 - 운영체제 (ex, Centos 6.5) 설치한다.
 - /etc/hosts 파일에 FQDN 이름을 정의한다.
 - 각 노드의 hostname 을 정의한다.
 - ssh-keygen 을 통해서 ambari server에서 키 인증 되도록 한다.
 - ntpd 를 설치해서 전체 노드의 시간을 동기화 한다.

2. ambari 서버를 구성한다.

3. amber UI에 접속해서 하둡 클러스터를 구성한다.


참고 이미지



2014년 8월 8일 금요일

sample code to control the data in hadoop framework.

1. flume

-- fox.conf
# Name the components on this agent
# fox -> zoo -> koala
agent.sinks = koala
agent.sources = fox
agent.channels = zoo

# Describe/configure the source
agent.sources.fox.type = spooldir
agent.sources.fox.spoolDir = /home/flume/dump

# Describe the sink
agent.sinks.koala.type = hdfs
agent.sinks.koala.hdfs.path = /flume/events
agent.sinks.koala.hdfs.fileType = DataStream
agent.sinks.koala.hdfs.writeFormat = Text
agent.sinks.koala.hdfs.rollSize = 0
agent.sinks.koala.hdfs.rollCount = 10000

# Use a channel which buffers events in memory
agent.channels.zoo.type = file

# Bind the source and sink to the channel
agent.sources.fox.channels = zoo
agent.sinks.koala.channel = zoo

-- beginning with configuration (fox.conf)
shell$ flume-ng agent --conf conf --conf-file fox.conf --name agent


2. hcatalog

hcat -e "create table koala (cnt bigint, wd string)"


3. pig

a = load '/flume/events/*';
b = foreach a generate flatten(TOKENIZE((chararray)$0)) as word;
c = group b by word;
d = foreach c generate COUNT(b) as cnt, group as wd;
store d into 'koala' using org.apache.hcatalog.pig.HCatStorer();


4. hive

select wd, cnt from koala order by cnt desc limit 10;

2014년 4월 28일 월요일

how to use bzip2 that supports a splittable compression with hadoop-streaming package.

sample codes for testing

1. compression

# To make a compress files per block by mapper.
hadoop jar hadoop-streaming-2.2.0.2.1.0.0-92.jar \
    -D mapreduce.output.fileoutputformat.compress=TRUE \
    -D mapreduce.output.fileoutputformat.compress.type=RECORD \
    -D mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.BZip2Codec \
    -D mapreduce.job.reduces=0 \
    -mapper /bin/cat \
    -input <input files> \
    -output <output directory> \
#    -outputformat org.apache.hadoop.mapred.SequenceFileOutputFormat

# To make one compress files
hadoop jar hadoop-streaming-2.2.0.2.1.0.0-92.jar \
    -D mapreduce.output.fileoutputformat.compress=TRUE \
    -D mapreduce.output.fileoutputformat.compress.type=RECORD \
    -D mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.BZip2Codec \
    -D mapreduce.job.reduces=1 \
    -mapper /bin/cat \
    -reducer /bin/cat \ 
    -input <input files> \
    -output <output directory> \

# To make a compress files per block by mapper into a special block size.
- Pig
set output.compression.enabled true;
set output.compression.codec org.apache.hadoop.io.compress.BZip2Codec;
A = LOAD '/lab/efdc/EFDC_2010020100.nc' USING PigStorage();
SET dfs.block.size 36700160;
STORE A INTO '/lab/Dave/output/pig.nc' USING PigStorage();

# copy a file to new file to some block size
hadoop fs -D dfs.block.size=36700160 -cp <source directory> <target directory>


2. decompression & analysis

hadoop jar hadoop-streaming-2.2.0.2.1.0.0-92.jar \
        -D mapred.input.compress=true \
        -D mapred.input.compression.codec=org.apache.hadoop.io.compress.BZip2Codec \
        -files ./mapper.py,./reducer.py -mapper ./mapper.py -reducer ./reducer.py \
        -input <bzip2 compressed files> -output <output directory>

3. ETC
# below properties was deprecated to next below.
    -D mapred.input.compress=TRUE \
    -D mapred.input.compress.type=BLOCK \
    -D mapred.input.compress.codec=org.apache.hadoop.io.compress.BZip2Codec \
# next below
    -D mapreduce.output.fileoutputformat.compress=TRUE \
    -D mapreduce.output.fileoutputformat.compress.type=BLOCK \
    -D mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.BZip2Codec \

Deprecated List up ~
http://archive.cloudera.com/cdh4/cdh/4/hadoop-2.0.0-cdh4.1.2/hadoop-project-dist/hadoop-common/DeprecatedProperties.html

# block size as default
hdfs getconf -confKey dfs.blocksize

# block size as activity
hadoop fs -stat %o <hdfs drectory>