ファイル分類
はじめてのpigメモ
複数のファイルから種別毎にファイルを分類する
logfile1
type | message |
---|---|
LOG0001 | MESSAGE1 |
LOG0001 | MESSAGE2 |
... | ... |
LOG0004 | MESSAGE15 |
logfile2 ... 4
pigコマンド
pig -x local
-x local でローカル実行(なしでhadoopモード)
- Pig Latin
ファイルをロード
logfile = LOAD '/home/hadoop/logfile[0-9]'
USING PigStorage('\t') AS (
type:chararray,
message:chararray);
USING PigStorageで区切り文字指定
ASでカラム名の指定
分割
SPLIT logfile
INTO
log1 IF type == 'LOG0001';
SPLIT INTO で条件毎にファイルを分割できる
DUMPで標準出力
DUMP log1;
(LOG0001,Message1)
(LOG0001,Message2)
(LOG0001,Message3)
...
STOREで指定ディレクトリに出力(ファイル名は自動)
STORE log1 INTO 'LOG0001' USING PigStorage();
./ --> LOG0001/ --> part-m-00000
ファイルで実行できる
[pigscript]
logfile = LOAD '/home/hadoop/logfile[0-9]'
USING PigStorage('\t') AS (
type:chararray,
message:chararray);
SPLIT logfile
INTO
log1 IF type == 'LOG0001',
log2 IF type == 'LOG0002',
log3 IF type == 'LOG0003',
log4 IF type == 'LOG0004';
STORE log1 INTO 'LOG0001' USING PigStorage();
STORE log2 INTO 'LOG0002' USING PigStorage();
STORE log3 INTO 'LOG0003' USING PigStorage();
STORE log4 INTO 'LOG0004' USING PigStorage();
# pig -x local -f pigscript