LTSV を Apache Pig で読むための UDF がほぼできたよ

LTSVApache Pig で読むための UDF がほぼできました。

作り始めた時点から追加した機能は、マップを作らずに値を直接フィールドに読み込めるようにしたことです。

入力データ (列区切りはタブ):

host:host1.example.org   req:GET /index.html   ua:Opera/9.80
host:host1.example.org   req:GET /favicon.ico  ua:Opera/9.80
host:pc.example.com      req:GET /news.html    ua:Mozilla/5.0

プログラム:

-- JAR を登録
REGISTER pig-ltsv-storage-201302111743.jar;

-- ファイルを読み込んで、 (host 列, ua 列) ごとの数を数える
access = LOAD 'access.log'
    USING org.ltsv.pig.LTSVLoader('host:chararray, ua:chararray');
grouped_access = GROUP access BY (host, ua);
count_for_host_ua = FOREACH grouped_access
    GENERATE group.host, group.ua, COUNT(access);

-- 結果を表示
DUMP count_for_host_ua;

結果:

(host1.example.org,Opera/9.80,2)
(pc.example.com,Firefox/5.0,1)

今はテスト書きなおしてます。