log = load '$INFILE' using PigStorage('\t');
define tracking_parser `/usr/ruby parse_click.rb --map` SHIP('parse_click.rb', 'click_tracking.rb');
strmo = stream log through tra_parser;
store strmo into '$OUTFILE' using PigStorage('\t');
require 'wukong'
require 'json'
require './click_tra.rb'
module ParseClick
class Mapper Wukong::Streamer::RecordStreamer
def before_stream
@bad_count = 0
end
def after_stream
raise RuntimeError, "Exceeded bad records : #{@bad_count}" if @bad_count > 10
end
def process *records
yield ClickTra.new(JSON.parse(records[2])).to_a
rescue => e
@bad_count += 1
warn "Bad record #{e}: #{records[2]}"
end
end
end
Wukong.run ParseClick::Mapper, nil
require 'date'
require './models.rb'
class ClickTra
output :ip
output :c_date
#output your other atrributes
def c_date
click_date.strftime("%Y%m%d").to_i
end
def ip
browser_ip.to_i
end
end