Package com.packetloop.packetpig.udf.geoip

Source Code of com.packetloop.packetpig.udf.geoip.Country

package com.packetloop.packetpig.udf.geoip;

import com.maxmind.geoip.LookupService;
import org.apache.pig.EvalFunc;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.data.Tuple;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Country extends EvalFunc<String> {

    private LookupService cl;

    public Country() throws IOException {
        try {
            cl = new LookupService("data/GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE);
        } catch (FileNotFoundException ignored) {
            cl = new LookupService("GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE);
        }
    }

    public List<String> getCacheFiles() {
        List<String> s = new ArrayList<String>();
        s.add("hdfs:///packetpig/GeoIP.dat#GeoIP.dat");
        return s;
    }

    @Override
    public String exec(Tuple input) throws ExecException {
        return cl.getCountry((String)input.get(0)).getCode();
    }
}
TOP

Related Classes of com.packetloop.packetpig.udf.geoip.Country

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.